Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions rust/log-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,6 @@ impl wal3::MarkDirty for MarkDirty {
}
}

////////////////////////////////////// storage_prefix_for_log //////////////////////////////////////

pub fn storage_prefix_for_log(collection: CollectionUuid) -> String {
format!("logs/{}", collection)
}

///////////////////////////////////////////// LogServer ////////////////////////////////////////////

pub struct LogServer {
Expand Down Expand Up @@ -647,7 +641,7 @@ impl LogServer {
}
})
.collect::<Result<Vec<_>, Status>>()?;
let prefix = storage_prefix_for_log(collection_id);
let prefix = collection_id.storage_prefix_for_log();
let mark_dirty = MarkDirty {
collection_id,
dirty_log: Arc::clone(&self.dirty_log),
Expand Down Expand Up @@ -676,7 +670,7 @@ impl LogServer {
.await?;
// Set it up so that once we release the mutex, the next person won't do I/O and will
// immediately be able to push logs.
let storage_prefix = storage_prefix_for_log(collection_id);
let storage_prefix = collection_id.storage_prefix_for_log();
let mark_dirty = MarkDirty {
collection_id,
dirty_log: Arc::clone(&self.dirty_log),
Expand Down Expand Up @@ -781,7 +775,7 @@ impl LogServer {
"update_collection_log_offset for {collection_id} to {}",
adjusted_log_offset
);
let storage_prefix = storage_prefix_for_log(collection_id);
let storage_prefix = collection_id.storage_prefix_for_log();

let log_reader = LogReader::new(
self.config.reader.clone(),
Expand Down Expand Up @@ -1020,12 +1014,12 @@ impl LogServer {
&self,
rollups: &mut HashMap<CollectionUuid, RollupPerCollection>,
) -> Result<(), Error> {
let load_cursor = |storage, collection_id| async move {
let load_cursor = |storage, collection_id: CollectionUuid| async move {
let cursor = &COMPACTION;
let cursor_store = CursorStore::new(
CursorStoreOptions::default(),
Arc::clone(storage),
storage_prefix_for_log(collection_id),
collection_id.storage_prefix_for_log(),
"rollup".to_string(),
);
let span = tracing::info_span!("cursor load", collection_id = ?collection_id);
Expand Down Expand Up @@ -1074,7 +1068,7 @@ impl LogServer {

async move {
tracing::info!("Pushing logs for collection {}", collection_id);
let prefix = storage_prefix_for_log(collection_id);
let prefix = collection_id.storage_prefix_for_log();
let key = LogKey { collection_id };
let handle = self.open_logs.get_or_create_state(key);
let mark_dirty = MarkDirty {
Expand Down Expand Up @@ -1151,7 +1145,7 @@ impl LogServer {
.map(CollectionUuid)
.map_err(|_| Status::invalid_argument("Failed to parse collection id"))?;
async move {
let prefix = storage_prefix_for_log(collection_id);
let prefix = collection_id.storage_prefix_for_log();
let log_reader = LogReader::new(
self.config.reader.clone(),
Arc::clone(&self.storage),
Expand Down Expand Up @@ -1237,7 +1231,7 @@ impl LogServer {
collection_id: CollectionUuid,
pull_logs: &PullLogsRequest,
) -> Result<Vec<Fragment>, wal3::Error> {
let prefix = storage_prefix_for_log(collection_id);
let prefix = collection_id.storage_prefix_for_log();
let log_reader = LogReader::new(
self.config.reader.clone(),
Arc::clone(&self.storage),
Expand Down Expand Up @@ -1284,7 +1278,7 @@ impl LogServer {
let futures = fragments
.iter()
.map(|fragment| async {
let prefix = storage_prefix_for_log(collection_id);
let prefix = collection_id.storage_prefix_for_log();
if let Some(cache) = self.cache.as_ref() {
let cache_key = format!("{collection_id}::{}", fragment.path);
let cache_span = tracing::info_span!("cache get", cache_key = ?cache_key);
Expand Down Expand Up @@ -1361,8 +1355,8 @@ impl LogServer {
let target_collection_id = Uuid::parse_str(&request.target_collection_id)
.map(CollectionUuid)
.map_err(|_| Status::invalid_argument("Failed to parse collection id"))?;
let source_prefix = storage_prefix_for_log(source_collection_id);
let target_prefix = storage_prefix_for_log(target_collection_id);
let source_prefix = source_collection_id.storage_prefix_for_log();
let target_prefix = target_collection_id.storage_prefix_for_log();
let storage = Arc::clone(&self.storage);
let options = self.config.writer.clone();

Expand Down Expand Up @@ -1612,7 +1606,7 @@ impl LogServer {
"Migrating log for collection {} to new log service",
collection_id
);
let prefix = storage_prefix_for_log(collection_id);
let prefix = collection_id.storage_prefix_for_log();
let key = LogKey { collection_id };
let handle = self.open_logs.get_or_create_state(key);
let mark_dirty = MarkDirty {
Expand Down Expand Up @@ -1673,7 +1667,7 @@ impl LogServer {
.map(CollectionUuid)
.map_err(|_| Status::invalid_argument("Failed to parse collection id"))?;
tracing::info!("inspect_log_state for {collection_id}");
let storage_prefix = storage_prefix_for_log(collection_id);
let storage_prefix = collection_id.storage_prefix_for_log();
let log_reader = LogReader::new(
self.config.reader.clone(),
Arc::clone(&self.storage),
Expand Down Expand Up @@ -2572,7 +2566,7 @@ mod tests {
#[test]
fn storage_prefix_for_log_format() {
let collection_id = CollectionUuid::new();
let prefix = storage_prefix_for_log(collection_id);
let prefix = collection_id.storage_prefix_for_log();
assert_eq!(format!("logs/{}", collection_id), prefix);
}

Expand Down
13 changes: 13 additions & 0 deletions rust/types/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ impl CollectionUuid {
pub fn new() -> Self {
CollectionUuid(Uuid::new_v4())
}

pub fn storage_prefix_for_log(&self) -> String {
format!("logs/{}", self)
}
}

impl std::str::FromStr for CollectionUuid {
Expand Down Expand Up @@ -375,4 +379,13 @@ mod test {
SystemTime::UNIX_EPOCH + Duration::new(1, 1)
);
}

#[test]
fn storage_prefix_for_log_format() {
let collection_id = Uuid::parse_str("34e72052-5e60-47cb-be88-19a9715b7026")
.map(CollectionUuid)
.unwrap();
let prefix = collection_id.storage_prefix_for_log();
assert_eq!("logs/34e72052-5e60-47cb-be88-19a9715b7026", prefix);
}
}
Loading