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

Non blocking client 2 #10

Merged
merged 9 commits into from
Mar 18, 2024
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
35 changes: 0 additions & 35 deletions .github/workflows/ci.yml

This file was deleted.

54 changes: 54 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI

on:
pull_request:
branches: [ main ]

jobs:
commit:
name: Commit Message Validation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- run: git show-ref
- uses: actions-rs/[email protected]
with:
crate: git-cz
version: latest
- name: Validate commit messages
run: git-cz check ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}

test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Start the cluster
run: ./scripts/quick_start.sh

- name: Run test
run: ./gradlew test

spell-check:
name: Spell Check
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v2

- name: Check Spelling
uses: crate-ci/typos@master
1 change: 1 addition & 0 deletions jxline-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ dependencies {
api(libs.jetcd)

testImplementation(libs.bundles.testing)
testRuntimeOnly(libs.bundles.log4j)
}
19 changes: 18 additions & 1 deletion jxline-core/src/main/java/cloud/xline/jxline/Client.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
package cloud.xline.jxline;

public interface Client extends io.etcd.jetcd.Client {
/**
* Xline client
*/
public interface Client {

/**
* Get the protocol client
*
* @return the {@link ProtocolClient}
*/
ProtocolClient getProtocolClient();

/**
* Get the kv client
*
* @return the {@link KV}
*/
KV getKVClient();

/**
* Override the jetcd.cloud.xline.client.Client.builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,11 @@ public ClientBuilder keepaliveTimeout(Duration keepaliveTimeout) {
return this;
}

/**
* Get Keepalive option for gRPC
*
* @return if this client uses gRPC keep alive without calls.
*/
public Boolean keepaliveWithoutCalls() {
return keepaliveWithoutCalls;
}
Expand Down
112 changes: 112 additions & 0 deletions jxline-core/src/main/java/cloud/xline/jxline/KV.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright 2016-2021 The jetcd authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cloud.xline.jxline;

import cloud.xline.jxline.kv.*;
import io.etcd.jetcd.ByteSequence;
import io.etcd.jetcd.options.CompactOption;
import io.etcd.jetcd.options.DeleteOption;
import io.etcd.jetcd.options.GetOption;
import io.etcd.jetcd.options.PutOption;
import io.etcd.jetcd.support.CloseableClient;

import java.util.concurrent.CompletableFuture;

/** Interface of kv client talking to xline. */
public interface KV extends CloseableClient {

/**
* put a key-value pair into etcd.
*
* @param key key in ByteSequence
* @param value value in ByteSequence
* @return PutResponse
*/
CompletableFuture<PutResponse> put(ByteSequence key, ByteSequence value);

/**
* put a key-value pair into etcd with option.
*
* @param key key in ByteSequence
* @param value value in ByteSequence
* @param option PutOption
* @return PutResponse
*/
CompletableFuture<PutResponse> put(ByteSequence key, ByteSequence value, PutOption option);

/**
* retrieve value for the given key.
*
* @param key key in ByteSequence
* @return GetResponse
*/
CompletableFuture<GetResponse> get(ByteSequence key);

/**
* retrieve keys with GetOption.
*
* @param key key in ByteSequence
* @param option GetOption
* @return GetResponse
*/
CompletableFuture<GetResponse> get(ByteSequence key, GetOption option);

/**
* delete a key.
*
* @param key key in ByteSequence
* @return DeleteResponse
*/
CompletableFuture<DeleteResponse> delete(ByteSequence key);

/**
* delete a key or range with option.
*
* @param key key in ByteSequence
* @param option DeleteOption
* @return DeleteResponse
*/
CompletableFuture<DeleteResponse> delete(ByteSequence key, DeleteOption option);

/**
* compact etcd KV history before the given rev.
*
* <p>All superseded keys with a revision less than the compaction revision will be removed.
*
* @param rev the revision to compact.
* @return CompactResponse
*/
CompletableFuture<CompactResponse> compact(long rev);

/**
* compact etcd KV history before the given rev with option.
*
* <p>All superseded keys with a revision less than the compaction revision will be removed.
*
* @param rev etcd revision
* @param option CompactOption
* @return CompactResponse
*/
CompletableFuture<CompactResponse> compact(long rev, CompactOption option);

/**
* creates a transaction.
*
* @return a Txn
*/
Txn txn();
}
93 changes: 93 additions & 0 deletions jxline-core/src/main/java/cloud/xline/jxline/KeyValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright 2016-2021 The jetcd authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cloud.xline.jxline;

import io.etcd.jetcd.ByteSequence;
import io.etcd.jetcd.support.Util;

/** Etcd key value pair. */
public class KeyValue {

private final com.xline.protobuf.KeyValue kv;
private final ByteSequence unprefixedKey;
private final ByteSequence value;

public KeyValue(com.xline.protobuf.KeyValue kv, ByteSequence namespace) {
this.kv = kv;
this.value = ByteSequence.from(kv.getValue());

this.unprefixedKey =
ByteSequence.from(
kv.getKey().isEmpty()
? kv.getKey()
: Util.unprefixNamespace(kv.getKey(), namespace));
}

/**
* Returns the key
*
* @return the key.
*/
public ByteSequence getKey() {
return unprefixedKey;
}

/**
* Returns the value
*
* @return the value.
*/
public ByteSequence getValue() {
return value;
}

/**
* Returns the create revision.
*
* @return the create revision.
*/
public long getCreateRevision() {
return kv.getCreateRevision();
}

/**
* Returns the mod revision.
*
* @return the mod revision.
*/
public long getModRevision() {
return kv.getModRevision();
}

/**
* Returns the version.
*
* @return the version.
*/
public long getVersion() {
return kv.getVersion();
}

/**
* Returns the lease.
*
* @return the lease.
*/
public long getLease() {
return kv.getLease();
}
}
14 changes: 14 additions & 0 deletions jxline-core/src/main/java/cloud/xline/jxline/ProtocolClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cloud.xline.jxline;

import com.xline.protobuf.Command;
import com.xline.protobuf.CommandResponse;
import com.xline.protobuf.SyncResponse;
import io.etcd.jetcd.support.CloseableClient;

import java.util.concurrent.CompletableFuture;
import java.util.function.BiFunction;

public interface ProtocolClient extends CloseableClient {
<T> CompletableFuture<T> propose(
Command cmd, boolean useFastPath, BiFunction<CommandResponse, SyncResponse, T> convert);
}
Loading
Loading