Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 76d9bf1

Browse files
committed
allow setting max db size on namespace create
1 parent b6643a0 commit 76d9bf1

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

sqld/src/http/admin/mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ struct HttpDatabaseConfig {
8686
max_db_size: Option<bytesize::ByteSize>,
8787
}
8888

89-
#[derive(Debug, Deserialize)]
90-
struct CreateNamespaceReq {
91-
dump_url: Option<Url>,
92-
}
93-
9489
async fn handle_post_config<M: MakeNamespace>(
9590
State(app_state): State<Arc<AppState<M>>>,
9691
Path(namespace): Path<String>,
@@ -113,6 +108,12 @@ async fn handle_post_config<M: MakeNamespace>(
113108
Ok(())
114109
}
115110

111+
#[derive(Debug, Deserialize)]
112+
struct CreateNamespaceReq {
113+
dump_url: Option<Url>,
114+
max_db_size: Option<bytesize::ByteSize>,
115+
}
116+
116117
async fn handle_create_namespace<M: MakeNamespace>(
117118
State(app_state): State<Arc<AppState<M>>>,
118119
Path(namespace): Path<String>,
@@ -123,10 +124,16 @@ async fn handle_create_namespace<M: MakeNamespace>(
123124
None => RestoreOption::Latest,
124125
};
125126

126-
app_state
127-
.namespaces
128-
.create(NamespaceName::from_string(namespace)?, dump)
129-
.await?;
127+
let namespace = NamespaceName::from_string(namespace)?;
128+
app_state.namespaces.create(namespace.clone(), dump).await?;
129+
130+
if let Some(max_db_size) = req.max_db_size {
131+
let store = app_state.namespaces.config_store(namespace).await?;
132+
let mut config = (*store.get()).clone();
133+
config.max_db_pages = max_db_size.as_u64() / LIBSQL_PAGE_SIZE;
134+
store.store(config)?;
135+
}
136+
130137
Ok(())
131138
}
132139

sqld/src/namespace/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ impl Namespace<PrimaryDatabase> {
728728
.await?;
729729

730730
let db_config_store = Arc::new(
731-
dbg!(DatabaseConfigStore::load(&db_path)).context("Could not load database config")?,
731+
DatabaseConfigStore::load(&db_path).context("Could not load database config")?,
732732
);
733733

734734
let connection_maker: Arc<_> = MakeLibSqlConn::new(

sqld/src/replication/primary/logger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,14 +856,14 @@ impl ReplicationLogger {
856856
let data_file = File::open(&data_path)?;
857857
let size = data_path.metadata()?.len();
858858
assert!(
859-
size % LIBSQL_PAGE_SIZE as u64 == 0,
859+
size % LIBSQL_PAGE_SIZE == 0,
860860
"database file size is not a multiple of page size"
861861
);
862862
let num_page = size / LIBSQL_PAGE_SIZE;
863863
let mut buf = [0; LIBSQL_PAGE_SIZE as usize];
864864
let mut page_no = 1; // page numbering starts at 1
865865
for i in 0..num_page {
866-
data_file.read_exact_at(&mut buf, i * LIBSQL_PAGE_SIZE as u64)?;
866+
data_file.read_exact_at(&mut buf, i * LIBSQL_PAGE_SIZE)?;
867867
log_file.push_page(&WalPage {
868868
page_no,
869869
size_after: if i == num_page - 1 { num_page as _ } else { 0 },

0 commit comments

Comments
 (0)