Skip to content

Commit

Permalink
Migrate db log paths
Browse files Browse the repository at this point in the history
  • Loading branch information
mamcx committed Jun 13, 2024
1 parent 44832f2 commit 41a92b8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/client-api/src/routes/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ where
))?;
let instance_id = database_instance.id;

let filepath = DatabaseLogger::filepath(&address, instance_id);
let filepath = DatabaseLogger::filepath(instance_id);
let lines = DatabaseLogger::read_latest(&filepath, num_lines).await;

let body = if follow {
Expand Down
9 changes: 3 additions & 6 deletions crates/core/src/database_logger.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use core::str::FromStr;
use spacetimedb_lib::address::Address;
use std::fs::OpenOptions;
use std::fs::{self, File};
use std::io::{self, prelude::*, SeekFrom};
Expand Down Expand Up @@ -126,11 +125,9 @@ impl DatabaseLogger {
// PathBuf::from(path)
// }

pub fn filepath(address: &Address, instance_id: u64) -> PathBuf {
let root = crate::stdb_path("worker_node/database_instances");
root.join(&*address.to_hex())
.join(instance_id.to_string())
.join("module_logs")
pub fn filepath(instance_id: u64) -> PathBuf {
let root = crate::stdb_path("database_instances");
root.join(instance_id.to_string()).join("module_logs")
}

pub fn open(root: impl AsRef<Path>) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/host/host_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ async fn make_dbic(
instance_id: u64,
relational_db: Arc<RelationalDB>,
) -> anyhow::Result<DatabaseInstanceContext> {
let log_path = DatabaseLogger::filepath(&database.address, instance_id);
let log_path = DatabaseLogger::filepath(instance_id);
let logger = tokio::task::block_in_place(|| Arc::new(DatabaseLogger::open(log_path)));
let subscriptions = ModuleSubscriptions::new(relational_db.clone(), database.owner_identity);

Expand Down
2 changes: 1 addition & 1 deletion crates/testing/src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl ModuleHandle {
}

pub async fn read_log(&self, size: Option<u32>) -> String {
let filepath = DatabaseLogger::filepath(&self.db_address, self.client.database_instance_id);
let filepath = DatabaseLogger::filepath(self.client.database_instance_id);
DatabaseLogger::read_latest(&filepath, size).await
}
}
Expand Down

0 comments on commit 41a92b8

Please sign in to comment.