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

Support db with ttl open #227

Merged
merged 15 commits into from
Oct 24, 2018
Merged

Conversation

fredchenbj
Copy link
Member

Support DBWithTTL::Open interface, and add open_cf_with_ttl in rocksdb.rs

@DorianZheng
Copy link

DorianZheng commented Oct 17, 2018

@fredchenbj Thank you for the PR, I will take a look ASAP. #225

@DorianZheng
Copy link

@fredchenbj CI failed because there are somethings wrong with the code format. Could you run make format and commit it again?

@fredchenbj
Copy link
Member Author

@DorianZheng OK, I will run make format and commit it again.

@fredchenbj
Copy link
Member Author

@fredchenbj CI failed because there are somethings wrong with the code format. Could you run make format and commit it again?

@fredchenbj fredchenbj closed this Oct 17, 2018
@fredchenbj fredchenbj reopened this Oct 17, 2018
src/rocksdb.rs Outdated
}

pub fn open_cf_with_ttl<'a, T>(opts: DBOptions, path: &str, cfds: Vec<T>, ttls: &[i32]) ->Result<DB, String>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use cargo fmt --all

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I have committed it again.

@siddontang
Copy link

PTAL @DorianZheng @solotzg

const char** column_family_names,
const crocksdb_options_t** column_family_options,
crocksdb_column_family_handle_t** column_family_handles,
const int32_t* ttl_array,
Copy link

@DorianZheng DorianZheng Oct 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put ttl_array and read_only before column_family_handles, cause it's a input parameter.

FYI: https://google.github.io/styleguide/cppguide.html#Output_Parameters

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parameter order is according to the declaration of Open function in rocksdb/include/rocksdb/utilities/db_ttl.h. If it is better to conform to google cpp style, I will change it.

src/rocksdb.rs Outdated
@@ -441,34 +463,56 @@ impl DB {
} else {
false
};
let with_ttl = if ttls.len() > 0 && ttls.len() == cf_names.len() {
Copy link

@DorianZheng DorianZheng Oct 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's a misuse when ttls.len() != cf_names.len() but ttls.len() > 0). Maybe it's better to throw error and let user to handle it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will fix it.

@DorianZheng
Copy link

@fredchenbj The implementation looks good overall. I left some comment. PTAL

@fredchenbj
Copy link
Member Author

@DorianZheng According to your comments, I have fixed both and committed it again. PTAL

src/rocksdb.rs Outdated
if ttls.len() > 0 {
DB::open_cf_with_ttl(opts, path, cfds, ttls)
} else {
DB::open_cf(opts, path, cfds)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone calls this function without giving ttls, it must be a misuse

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition is redundent here, I will remove it. Thus put all ttls conditions in open_cf_internal, and would throw error if not pass .

src/rocksdb.rs Outdated
let contains = list.iter().any(|ref cf| cf.is_default());
if !contains {
list.push(ColumnFamilyDescriptor::default());
if ttls.len() < list.len() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the length of the original list equals to the length of the original ttls, we should add ttl for default column family

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't matter here, if the length of the original list doesn't equal to the length of the original ttls, it will throw error in open_cf_internal.

Copy link

@DorianZheng DorianZheng Oct 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if user just don't use ttl open here? looks like you will add ttl for default column family here anyway

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this will add ttl, but it doesn't affect for with_ttl would be false, and not use ttl. This logic is ok here, but would not be clear, so I will add condition test here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that we can simplify with_ttl too, it's a little bit confusing. Do you think it's better like:

let with_ttl = if ttls_vec.len() > 0 {
    if ttls_vec.len() == cf_names.len() {
        true
    } else {
        return Err("the length of ttls not equal to length of cfs".to_owned());
    }
} else {
    false
}

Copy link
Member Author

@fredchenbj fredchenbj Oct 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, It's better. I will change to like this

let with_ttl = if ttls.len() > 0 { if ttls.len() == cfds.len() && ttls_vec.len() == cf_names.len() { true } else { return Err("the length of ttls not equal to length of cfs".to_owned()); } } else { false }

to make sure be not confusing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have commited it again.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about change the condition here FROM:

if ttls.len() < list.len() {

TO

if ttls.len() > 0 {

So that we can get rid of judging if ttls.len() > 0 when deal with with_ttl

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this way is more clear. I have changed and committed it.

let p = db.put_cf(cf1, b"k1", b"a");
assert!(p.is_ok());
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add test for when the length of ttlsis not equal to the length of column_families.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

Copy link

@DorianZheng DorianZheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thank you @fredchenbj for the PR, It's great. @solotzg PTAL

Copy link

@solotzg solotzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DorianZheng
Copy link

Merged.

@DorianZheng DorianZheng merged commit 8f27141 into tikv:master Oct 24, 2018
@fredchenbj fredchenbj changed the title Supoort db with ttl open Support db with ttl open Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants