-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from tansu-io/191-deleting-a-topic-with-confi…
…guration-causing-an-error-with-pg-storage fix: pg constraint while deleting topic with configuration
- Loading branch information
Showing
4 changed files
with
271 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
// Copyright ⓒ 2025 Peter Morgan <peter.james.morgan@gmail.com> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as | ||
// published by the Free Software Foundation, either version 3 of the | ||
// License, or (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
use common::{alphanumeric_string, register_broker}; | ||
use tansu_kafka_sans_io::{ | ||
create_topics_request::{CreatableTopic, CreatableTopicConfig}, | ||
ErrorCode, | ||
}; | ||
use tansu_server::Result; | ||
use tansu_storage::{Storage, StorageContainer, TopicId}; | ||
use tracing::debug; | ||
use uuid::Uuid; | ||
|
||
pub mod common; | ||
|
||
pub async fn create_delete( | ||
cluster_id: Uuid, | ||
broker_id: i32, | ||
mut sc: StorageContainer, | ||
) -> Result<()> { | ||
register_broker(&cluster_id, broker_id, &mut sc).await?; | ||
|
||
let topic_name: String = alphanumeric_string(15); | ||
debug!(?topic_name); | ||
|
||
let num_partitions = 6; | ||
let replication_factor = 0; | ||
|
||
let assignments = Some([].into()); | ||
let configs = Some([].into()); | ||
|
||
let topic_id = sc | ||
.create_topic( | ||
CreatableTopic { | ||
name: topic_name.clone(), | ||
num_partitions, | ||
replication_factor, | ||
assignments: assignments.clone(), | ||
configs: configs.clone(), | ||
}, | ||
false, | ||
) | ||
.await?; | ||
debug!(?topic_id); | ||
|
||
assert_eq!( | ||
ErrorCode::None, | ||
sc.delete_topic(&TopicId::from(topic_id)).await? | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
pub async fn create_with_config_delete( | ||
cluster_id: Uuid, | ||
broker_id: i32, | ||
mut sc: StorageContainer, | ||
) -> Result<()> { | ||
register_broker(&cluster_id, broker_id, &mut sc).await?; | ||
|
||
let topic_name: String = alphanumeric_string(15); | ||
debug!(?topic_name); | ||
|
||
let num_partitions = 6; | ||
let replication_factor = 0; | ||
|
||
let assignments = Some([].into()); | ||
let configs = Some( | ||
[CreatableTopicConfig { | ||
name: "xyz".into(), | ||
value: Some("12321".into()), | ||
}] | ||
.into(), | ||
); | ||
|
||
let topic_id = sc | ||
.create_topic( | ||
CreatableTopic { | ||
name: topic_name.clone(), | ||
num_partitions, | ||
replication_factor, | ||
assignments: assignments.clone(), | ||
configs: configs.clone(), | ||
}, | ||
false, | ||
) | ||
.await?; | ||
debug!(?topic_id); | ||
|
||
assert_eq!( | ||
ErrorCode::None, | ||
sc.delete_topic(&TopicId::from(topic_id)).await? | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
mod pg { | ||
use common::{init_tracing, StorageType}; | ||
use rand::{prelude::*, thread_rng}; | ||
use url::Url; | ||
|
||
use super::*; | ||
|
||
fn storage_container(cluster: impl Into<String>, node: i32) -> Result<StorageContainer> { | ||
Url::parse("tcp://127.0.0.1/") | ||
.map_err(Into::into) | ||
.and_then(|advertised_listener| { | ||
common::storage_container( | ||
StorageType::Postgres, | ||
cluster, | ||
node, | ||
advertised_listener, | ||
None, | ||
) | ||
}) | ||
} | ||
|
||
#[tokio::test] | ||
async fn create_delete() -> Result<()> { | ||
let _guard = init_tracing()?; | ||
|
||
let cluster_id = Uuid::now_v7(); | ||
let broker_id = thread_rng().gen_range(0..i32::MAX); | ||
|
||
super::create_delete( | ||
cluster_id, | ||
broker_id, | ||
storage_container(cluster_id, broker_id)?, | ||
) | ||
.await | ||
} | ||
|
||
#[tokio::test] | ||
async fn create_with_config_delete() -> Result<()> { | ||
let _guard = init_tracing()?; | ||
|
||
let cluster_id = Uuid::now_v7(); | ||
let broker_id = thread_rng().gen_range(0..i32::MAX); | ||
|
||
super::create_with_config_delete( | ||
cluster_id, | ||
broker_id, | ||
storage_container(cluster_id, broker_id)?, | ||
) | ||
.await | ||
} | ||
} | ||
|
||
mod in_memory { | ||
use common::{init_tracing, StorageType}; | ||
use rand::{prelude::*, thread_rng}; | ||
use url::Url; | ||
|
||
use super::*; | ||
|
||
fn storage_container(cluster: impl Into<String>, node: i32) -> Result<StorageContainer> { | ||
Url::parse("tcp://127.0.0.1/") | ||
.map_err(Into::into) | ||
.and_then(|advertised_listener| { | ||
common::storage_container( | ||
StorageType::InMemory, | ||
cluster, | ||
node, | ||
advertised_listener, | ||
None, | ||
) | ||
}) | ||
} | ||
|
||
#[tokio::test] | ||
async fn create_delete() -> Result<()> { | ||
let _guard = init_tracing()?; | ||
|
||
let cluster_id = Uuid::now_v7(); | ||
let broker_id = thread_rng().gen_range(0..i32::MAX); | ||
|
||
super::create_delete( | ||
cluster_id, | ||
broker_id, | ||
storage_container(cluster_id, broker_id)?, | ||
) | ||
.await | ||
} | ||
|
||
#[tokio::test] | ||
async fn create_with_config_delete() -> Result<()> { | ||
let _guard = init_tracing()?; | ||
|
||
let cluster_id = Uuid::now_v7(); | ||
let broker_id = thread_rng().gen_range(0..i32::MAX); | ||
|
||
super::create_with_config_delete( | ||
cluster_id, | ||
broker_id, | ||
storage_container(cluster_id, broker_id)?, | ||
) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
tansu-storage/src/pg/topic_configuration_delete_by_topic.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-- -*- mode: sql; sql-product: postgres; -*- | ||
-- Copyright ⓒ 2025 Peter Morgan <peter.james.morgan@gmail.com> | ||
-- | ||
-- This program is free software: you can redistribute it and/or modify | ||
-- it under the terms of the GNU Affero General Public License as | ||
-- published by the Free Software Foundation, either version 3 of the | ||
-- License, or (at your option) any later version. | ||
-- | ||
-- This program is distributed in the hope that it will be useful, | ||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
-- GNU Affero General Public License for more details. | ||
-- | ||
-- You should have received a copy of the GNU Affero General Public License | ||
-- along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
delete from topic_configuration | ||
using cluster c, topic t | ||
where c.name = $1 | ||
and t.name = $2 | ||
and t.cluster = c.id | ||
and topic_configuration.topic = t.id; |