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) contains key api #302

Merged
merged 7 commits into from
Oct 22, 2019
Merged

Conversation

SteNicholas
Copy link
Contributor

Motivation:

Provide containsKey(byte[] key) method similar to get(byte[] key) etc.

Modification:

RheaKVStore provide containsKey(byte[] key) method similar to get(byte[] key) etc.

CompletableFuture<Boolean> containsKey(final byte[] key);

Boolean bContainsKey(final byte[] key);

Result:

Fixes #290

}

private void internalContainsKey(final byte[] key, final CompletableFuture<Boolean> future,
final int retriesLeft, final Errors lastCause) {
Copy link
Contributor

Choose a reason for hiding this comment

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

这一行没有格式化

/**
* Returns whether database contains the specified input key.
*
* @param key the specified key database contains.
Copy link
Contributor

Choose a reason for hiding this comment

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

格式化

public void containsKey(final byte[] key, final KVStoreClosure closure) {
final Timer.Context timeCtx = getTimeContext("CONTAINS_KEY");
try {
final Boolean isContains = this.defaultDB.containsKey(key);
Copy link
Contributor

Choose a reason for hiding this comment

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

final boolean exists = this.defaultDB.containsKey(key);

@@ -153,7 +153,8 @@ private void doStatistics() {
KVMetrics.counter(REGION_BYTES_WRITTEN, id).inc(this.bytesWritten);
break;
}
case KVOperation.GET: {
case KVOperation.GET:
case KVOperation.CONTAINS_KEY: {
Copy link
Contributor

Choose a reason for hiding this comment

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

CastException

final Lock readLock = this.readWriteLock.readLock();
readLock.lock();
try {
final Boolean isContains = this.db.keyMayExist(key, new StringBuilder(0));
Copy link
Contributor

Choose a reason for hiding this comment

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

final boolean exists = this.db.keyMayExist(key, new StringBuilder(0));

readLock.lock();
try {
final boolean exists = this.db.keyMayExist(key, new StringBuilder(0));
setSuccess(closure, exists);
Copy link
Contributor

Choose a reason for hiding this comment

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

boolean exists = false;
if (this.db.keyMayExist(key, new StringBuilder(0))) {
exists = this.db.get(key) != null;
}

应该是这样的逻辑

@fengjiachun fengjiachun merged commit 562abdc into sofastack:master Oct 22, 2019
luozhiyun993 pushed a commit to luozhiyun993/sofa-jraft that referenced this pull request Nov 25, 2019
* 'master' of https://github.com/sofastack/sofa-jraft:
  (feat) Remove multiple of 10ms for windows platform. (sofastack#351)
  (feat) add thread pool metric report (sofastack#339)
  [ISSUE#347]upgrade the com.fasterxml.jackson.core:jackson-databind to version 2.9.10.1. (sofastack#352)
  (feat) Support readIndex from learner (sofastack#343)
  (feat) counter example (sofastack#318)
  minor fixes (sofastack#336)
  Impl learner for jraft, sofastack#8 (sofastack#312)
  (fix) Declare rpcClient to be volatile, fix sofastack#319 (sofastack#323)
  (feat) add current leader id to node describe (sofastack#322)
  (fix) fix remove metric failed on replicator destroy (sofastack#325)
  (fix) raft options copy (sofastack#321)
  (feat) contains key api (sofastack#302)
  (feat) add rocksdb table_format_config and statistics (sofastack#295)
  feat/async snapshot (sofastack#287)
  fix/state listener (sofastack#285)
@fengjiachun fengjiachun mentioned this pull request Nov 29, 2019
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add containsKey API for rheakv
2 participants