forked from YahooArchive/bookkeeper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the client api to a type-safe api (YahooArchive#15)
- Loading branch information
Showing
66 changed files
with
2,809 additions
and
519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
api/src/main/java/org/apache/distributedlog/api/kv/Txn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.distributedlog.api.kv; | ||
|
||
|
||
import java.util.concurrent.CompletableFuture; | ||
import org.apache.distributedlog.api.kv.op.CompareOp; | ||
import org.apache.distributedlog.api.kv.op.Op; | ||
import org.apache.distributedlog.api.kv.result.TxnResult; | ||
|
||
/** | ||
* Txn is the interface that wraps mini-transactions. | ||
* | ||
* <h3>Usage examples</h3> | ||
* | ||
* <pre>{@code | ||
* txn.If( | ||
* new Cmp(KEY, Cmp.Op.GREATER, CmpTarget.value(VALUE)), | ||
* new Cmp(KEY, cmp.Op.EQUAL, CmpTarget.version(2)) | ||
* ).Then( | ||
* Op.put(KEY2, VALUE2, PutOption.DEFAULT), | ||
* Op.put(KEY3, VALUE3, PutOption.DEFAULT) | ||
* ).Else( | ||
* Op.put(KEY4, VALUE4, PutOption.DEFAULT), | ||
* Op.put(KEY4, VALUE4, PutOption.DEFAULT) | ||
* ).commit(); | ||
* }</pre> | ||
* | ||
* <p>Txn also supports If, Then, and Else chaining. e.g. | ||
* <pre>{@code | ||
* txn.If( | ||
* new Cmp(KEY, Cmp.Op.GREATER, CmpTarget.value(VALUE)) | ||
* ).If( | ||
* new Cmp(KEY, cmp.Op.EQUAL, CmpTarget.version(VERSION)) | ||
* ).Then( | ||
* Op.put(KEY2, VALUE2, PutOption.DEFAULT) | ||
* ).Then( | ||
* Op.put(KEY3, VALUE3, PutOption.DEFAULT) | ||
* ).Else( | ||
* Op.put(KEY4, VALUE4, PutOption.DEFAULT) | ||
* ).Else( | ||
* Op.put(KEY4, VALUE4, PutOption.DEFAULT) | ||
* ).commit(); | ||
* }</pre> | ||
*/ | ||
public interface Txn<K, V> { | ||
|
||
/** | ||
* takes a list of comparison. If all comparisons passed in succeed, | ||
* the operations passed into Then() will be executed. Or the operations | ||
* passed into Else() will be executed. | ||
*/ | ||
// CHECKSTYLE.OFF: MethodName | ||
Txn<K, V> If(CompareOp<K, V>... cmps); | ||
// CHECKSTYLE.ON: MethodName | ||
|
||
/** | ||
* takes a list of operations. The Ops list will be executed, if the | ||
* comparisons passed in If() succeed. | ||
*/ | ||
// CHECKSTYLE.OFF: MethodName | ||
Txn<K, V> Then(Op<K, V>... ops); | ||
// CHECKSTYLE.ON: MethodName | ||
|
||
/** | ||
* takes a list of operations. The Ops list will be executed, if the | ||
* comparisons passed in If() fail. | ||
*/ | ||
// CHECKSTYLE.OFF: MethodName | ||
Txn<K, V> Else(Op<K, V>... ops); | ||
// CHECKSTYLE.OFF: MethodName | ||
|
||
/** | ||
* tries to commit the transaction. | ||
* | ||
* @return a TxnResponse wrapped in CompletableFuture | ||
*/ | ||
CompletableFuture<TxnResult<K, V>> commit(); | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
api/src/main/java/org/apache/distributedlog/api/kv/op/CompareOp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.distributedlog.api.kv.op; | ||
|
||
import org.apache.bookkeeper.common.annotation.InterfaceAudience.Public; | ||
import org.apache.bookkeeper.common.annotation.InterfaceStability.Evolving; | ||
|
||
/** | ||
* A compare operator used in a {@link org.apache.distributedlog.api.kv.Txn}. | ||
* | ||
* @param <K> key type | ||
* @param <V> value type | ||
*/ | ||
@Public | ||
@Evolving | ||
public interface CompareOp<K, V> extends AutoCloseable { | ||
|
||
CompareTarget target(); | ||
|
||
CompareResult result(); | ||
|
||
K key(); | ||
|
||
V value(); | ||
|
||
long revision(); | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
api/src/main/java/org/apache/distributedlog/api/kv/op/CompareResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.distributedlog.api.kv.op; | ||
|
||
|
||
import org.apache.bookkeeper.common.annotation.InterfaceAudience.Public; | ||
import org.apache.bookkeeper.common.annotation.InterfaceStability.Evolving; | ||
|
||
/** | ||
* Define the compare result for a given {@link CompareOp}. | ||
*/ | ||
@Public | ||
@Evolving | ||
public enum CompareResult { | ||
EQUAL, | ||
GREATER, | ||
LESS, | ||
NOT_EQUAL | ||
} |
31 changes: 31 additions & 0 deletions
31
api/src/main/java/org/apache/distributedlog/api/kv/op/CompareTarget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.distributedlog.api.kv.op; | ||
|
||
/** | ||
* Target to compare. | ||
*/ | ||
public enum CompareTarget { | ||
|
||
VERSION, | ||
CREATE, | ||
MOD, | ||
VALUE | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
api/src/main/java/org/apache/distributedlog/api/kv/op/DeleteOp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.distributedlog.api.kv.op; | ||
|
||
import org.apache.distributedlog.api.kv.options.DeleteOption; | ||
|
||
/** | ||
* A delete operator to delete a single key or a key range. | ||
* | ||
* @param <K> key type | ||
* @param <V> value type. | ||
*/ | ||
public interface DeleteOp<K, V> extends Op<K, V> { | ||
|
||
K key(); | ||
|
||
DeleteOption<K> option(); | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
api/src/main/java/org/apache/distributedlog/api/kv/op/Op.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.distributedlog.api.kv.op; | ||
|
||
import org.apache.bookkeeper.common.annotation.InterfaceAudience.Public; | ||
import org.apache.bookkeeper.common.annotation.InterfaceStability.Evolving; | ||
|
||
/** | ||
* Abstract Operation. | ||
*/ | ||
@Public | ||
@Evolving | ||
public interface Op<K, V> extends AutoCloseable { | ||
|
||
OpType type(); | ||
|
||
} |
Oops, something went wrong.