Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cubestore): Use separate column family for queue #6274

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 12 additions & 6 deletions rust/cubestore/cubestore/src/cachestore/cache_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,18 @@ impl<'a> BaseRocksTable for CacheItemRocksTable<'a> {
}
}

rocks_table_new!(CacheItem, CacheItemRocksTable, TableId::CacheItems, {
vec![
Box::new(CacheItemRocksIndex::ByPath),
Box::new(CacheItemRocksIndex::ByPrefix),
]
});
rocks_table_new!(
CacheItem,
CacheItemRocksTable,
TableId::CacheItems,
{
vec![
Box::new(CacheItemRocksIndex::ByPath),
Box::new(CacheItemRocksIndex::ByPrefix),
]
},
rocksdb::DEFAULT_COLUMN_FAMILY_NAME
);

#[derive(Hash, Clone, Debug)]
pub enum CacheItemIndexKey {
Expand Down
30 changes: 25 additions & 5 deletions rust/cubestore/cubestore/src/cachestore/cache_rocksstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::CubeError;
use async_trait::async_trait;

use futures_timer::Delay;
use rocksdb::{BlockBasedOptions, Options, DB};
use rocksdb::{BlockBasedOptions, ColumnFamilyDescriptor, Options, DB};

use crate::cachestore::compaction::CompactionPreloadedState;
use crate::cachestore::listener::RocksCacheStoreListener;
Expand All @@ -38,6 +38,8 @@ use std::sync::{Arc, Mutex};
use std::time::Duration;
use tokio::sync::broadcast::Sender;

pub const CACHESTORE_QUEUE_COLUMN_FAMILY_NAME: &str = "queue";

pub(crate) struct RocksCacheStoreDetails {}

impl RocksCacheStoreDetails {
Expand Down Expand Up @@ -74,10 +76,8 @@ impl RocksStoreDetails for RocksCacheStoreDetails {

let mut opts = Options::default();
opts.create_if_missing(true);
opts.create_missing_column_families(true);
opts.set_prefix_extractor(rocksdb::SliceTransform::create_fixed_prefix(13));
opts.set_compaction_filter_factory(compaction::MetaStoreCacheCompactionFactory::new(
compaction_state,
));
// Disable automatic compaction before migration, will be enabled later in after_migration
opts.set_disable_auto_compactions(true);

Expand All @@ -90,7 +90,27 @@ impl RocksStoreDetails for RocksCacheStoreDetails {

opts.set_block_based_table_factory(&block_opts);

DB::open(&opts, path)
let default_cf = {
let mut opts = Options::default();
opts.set_prefix_extractor(rocksdb::SliceTransform::create_fixed_prefix(13));
opts.set_compaction_filter_factory(compaction::MetaStoreCacheCompactionFactory::new(
compaction_state.clone(),
));

ColumnFamilyDescriptor::new(rocksdb::DEFAULT_COLUMN_FAMILY_NAME, opts)
};

let queue_cf = {
let mut opts = Options::default();
opts.set_prefix_extractor(rocksdb::SliceTransform::create_fixed_prefix(13));
opts.set_compaction_filter_factory(compaction::MetaStoreCacheCompactionFactory::new(
compaction_state,
));

ColumnFamilyDescriptor::new(CACHESTORE_QUEUE_COLUMN_FAMILY_NAME, opts)
};

DB::open_cf_descriptors(&opts, path, vec![default_cf, queue_cf])
.map_err(|err| CubeError::internal(format!("DB::open error for cachestore: {}", err)))
}

Expand Down
21 changes: 14 additions & 7 deletions rust/cubestore/cubestore/src/cachestore/queue_item.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::cache_rocksstore::CACHESTORE_QUEUE_COLUMN_FAMILY_NAME;
use crate::metastore::{
BaseRocksTable, IndexId, RocksEntity, RocksSecondaryIndex, RocksTable, TableId, TableInfo,
};
Expand Down Expand Up @@ -364,13 +365,19 @@ impl<'a> BaseRocksTable for QueueItemRocksTable<'a> {
}
}

rocks_table_new!(QueueItem, QueueItemRocksTable, TableId::QueueItems, {
vec![
Box::new(QueueItemRocksIndex::ByPath),
Box::new(QueueItemRocksIndex::ByPrefixAndStatus),
Box::new(QueueItemRocksIndex::ByPrefix),
]
});
rocks_table_new!(
QueueItem,
QueueItemRocksTable,
TableId::QueueItems,
{
vec![
Box::new(QueueItemRocksIndex::ByPath),
Box::new(QueueItemRocksIndex::ByPrefixAndStatus),
Box::new(QueueItemRocksIndex::ByPrefix),
]
},
CACHESTORE_QUEUE_COLUMN_FAMILY_NAME
);

#[derive(Hash, Clone, Debug)]
pub enum QueueItemIndexKey {
Expand Down
11 changes: 8 additions & 3 deletions rust/cubestore/cubestore/src/cachestore/queue_result.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::cache_rocksstore::CACHESTORE_QUEUE_COLUMN_FAMILY_NAME;
use crate::metastore::{
BaseRocksTable, IndexId, RocksEntity, RocksSecondaryIndex, RocksTable, TableId, TableInfo,
};
Expand Down Expand Up @@ -67,9 +68,13 @@ impl<'a> BaseRocksTable for QueueResultRocksTable<'a> {
}
}

rocks_table_new!(QueueResult, QueueResultRocksTable, TableId::QueueResults, {
vec![Box::new(QueueResultRocksIndex::ByPath)]
});
rocks_table_new!(
QueueResult,
QueueResultRocksTable,
TableId::QueueResults,
{ vec![Box::new(QueueResultRocksIndex::ByPath)] },
CACHESTORE_QUEUE_COLUMN_FAMILY_NAME
);

#[derive(Hash, Clone, Debug)]
pub enum QueueResultIndexKey {
Expand Down
18 changes: 12 additions & 6 deletions rust/cubestore/cubestore/src/metastore/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,18 @@ pub(crate) enum ChunkRocksIndex {
ReplayHandleId = 2,
}

rocks_table_impl!(Chunk, ChunkRocksTable, TableId::Chunks, {
vec![
Box::new(ChunkRocksIndex::PartitionId),
Box::new(ChunkRocksIndex::ReplayHandleId),
]
});
rocks_table_impl!(
Chunk,
ChunkRocksTable,
TableId::Chunks,
{
vec![
Box::new(ChunkRocksIndex::PartitionId),
Box::new(ChunkRocksIndex::ReplayHandleId),
]
},
rocksdb::DEFAULT_COLUMN_FAMILY_NAME
);

base_rocks_secondary_index!(Chunk, ChunkRocksIndex);

Expand Down
20 changes: 13 additions & 7 deletions rust/cubestore/cubestore/src/metastore/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,19 @@ pub(crate) enum IndexRocksIndex {

crate::base_rocks_secondary_index!(Index, IndexRocksIndex);

rocks_table_impl!(Index, IndexRocksTable, TableId::Indexes, {
vec![
Box::new(IndexRocksIndex::TableID),
Box::new(IndexRocksIndex::Name),
Box::new(IndexRocksIndex::MultiIndexId),
]
});
rocks_table_impl!(
Index,
IndexRocksTable,
TableId::Indexes,
{
vec![
Box::new(IndexRocksIndex::TableID),
Box::new(IndexRocksIndex::Name),
Box::new(IndexRocksIndex::MultiIndexId),
]
},
rocksdb::DEFAULT_COLUMN_FAMILY_NAME
);

#[derive(Hash, Clone, Debug)]
pub enum IndexIndexKey {
Expand Down
18 changes: 12 additions & 6 deletions rust/cubestore/cubestore/src/metastore/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,18 @@ pub enum JobRocksIndex {

base_rocks_secondary_index!(Job, JobRocksIndex);

rocks_table_impl!(Job, JobRocksTable, TableId::Jobs, {
vec![
Box::new(JobRocksIndex::RowReference),
Box::new(JobRocksIndex::ByShard),
]
});
rocks_table_impl!(
Job,
JobRocksTable,
TableId::Jobs,
{
vec![
Box::new(JobRocksIndex::RowReference),
Box::new(JobRocksIndex::ByShard),
]
},
rocksdb::DEFAULT_COLUMN_FAMILY_NAME
);

#[derive(Hash, Clone, Debug)]
pub enum JobIndexKey {
Expand Down
11 changes: 9 additions & 2 deletions rust/cubestore/cubestore/src/metastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub use rocks_table::*;
use crate::cluster::node_name_by_partition;
use async_trait::async_trait;
use log::info;
use rocksdb::{BlockBasedOptions, Env, MergeOperands, Options, DB};
use rocksdb::{BlockBasedOptions, ColumnFamilyDescriptor, Env, MergeOperands, Options, DB};
use serde::{Deserialize, Serialize};
use std::hash::Hash;
use std::{env, io::Cursor, sync::Arc};
Expand Down Expand Up @@ -1160,7 +1160,14 @@ impl RocksStoreDetails for RocksMetaStoreDetails {

opts.set_block_based_table_factory(&block_opts);

DB::open(&opts, path)
let default_cf = {
let mut opts = Options::default();
opts.set_prefix_extractor(rocksdb::SliceTransform::create_fixed_prefix(13));

ColumnFamilyDescriptor::new(rocksdb::DEFAULT_COLUMN_FAMILY_NAME, opts)
};

DB::open_cf_descriptors(&opts, path, vec![default_cf])
.map_err(|err| CubeError::internal(format!("DB::open error for metastore: {}", err)))
}

Expand Down
13 changes: 9 additions & 4 deletions rust/cubestore/cubestore/src/metastore/multi_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ pub(crate) enum MultiIndexRocksIndex {

crate::base_rocks_secondary_index!(MultiIndex, MultiIndexRocksIndex);

rocks_table_impl!(MultiIndex, MultiIndexRocksTable, TableId::MultiIndexes, {
vec![Box::new(MultiIndexRocksIndex::ByName)]
});
rocks_table_impl!(
MultiIndex,
MultiIndexRocksTable,
TableId::MultiIndexes,
{ vec![Box::new(MultiIndexRocksIndex::ByName)] },
rocksdb::DEFAULT_COLUMN_FAMILY_NAME
);

#[derive(Hash, Clone, Debug)]
pub enum MultiIndexIndexKey {
Expand Down Expand Up @@ -210,7 +214,8 @@ rocks_table_impl!(
Box::new(MultiPartitionRocksIndex::ByMultiIndexId),
Box::new(MultiPartitionRocksIndex::ByParentId),
]
}
},
rocksdb::DEFAULT_COLUMN_FAMILY_NAME
);

#[derive(Hash, Clone, Debug)]
Expand Down
24 changes: 15 additions & 9 deletions rust/cubestore/cubestore/src/metastore/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,21 @@ pub(crate) enum PartitionRocksIndex {
ParentPartitionId = 5,
}

rocks_table_impl!(Partition, PartitionRocksTable, TableId::Partitions, {
vec![
Box::new(PartitionRocksIndex::IndexId),
Box::new(PartitionRocksIndex::MultiPartitionId),
Box::new(PartitionRocksIndex::Active),
Box::new(PartitionRocksIndex::JustCreated),
Box::new(PartitionRocksIndex::ParentPartitionId),
]
});
rocks_table_impl!(
Partition,
PartitionRocksTable,
TableId::Partitions,
{
vec![
Box::new(PartitionRocksIndex::IndexId),
Box::new(PartitionRocksIndex::MultiPartitionId),
Box::new(PartitionRocksIndex::Active),
Box::new(PartitionRocksIndex::JustCreated),
Box::new(PartitionRocksIndex::ParentPartitionId),
]
},
rocksdb::DEFAULT_COLUMN_FAMILY_NAME
);

#[derive(Hash, Clone, Debug)]
pub enum PartitionIndexKey {
Expand Down
3 changes: 2 additions & 1 deletion rust/cubestore/cubestore/src/metastore/replay_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ rocks_table_impl!(
ReplayHandle,
ReplayHandleRocksTable,
TableId::ReplayHandles,
{ vec![Box::new(ReplayHandleRocksIndex::ByTableId),] }
{ vec![Box::new(ReplayHandleRocksIndex::ByTableId),] },
rocksdb::DEFAULT_COLUMN_FAMILY_NAME
);

#[derive(Hash, Clone, Debug)]
Expand Down
Loading