├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── NOTICE.txt ├── .gitignore ├── settings.gradle ├── accord-core └── src │ ├── main │ └── java │ │ └── accord │ │ ├── coordinate │ │ ├── StaleTopology.java │ │ ├── ExecutePath.java │ │ ├── Outcome.java │ │ ├── tracking │ │ │ ├── ResponseTracker.java │ │ │ ├── RequestStatus.java │ │ │ ├── ShardTracker.java │ │ │ ├── ShardOutcome.java │ │ │ ├── PreAcceptExclusiveSyncPointTracker.java │ │ │ └── PreAcceptTracker.java │ │ ├── EpochTimeout.java │ │ ├── Truncated.java │ │ ├── Invalidated.java │ │ ├── PersistSyncPoint.java │ │ ├── StabiliseSyncPoint.java │ │ ├── Preempted.java │ │ ├── Redundant.java │ │ └── ProposeTxn.java │ │ ├── messages │ │ ├── Message.java │ │ ├── ReplyContext.java │ │ ├── Request.java │ │ ├── SimpleReply.java │ │ ├── Callback.java │ │ └── Reply.java │ │ ├── primitives │ │ ├── WithQuorum.java │ │ ├── EpochSupplier.java │ │ ├── FullRoute.java │ │ ├── Unseekable.java │ │ ├── Seekable.java │ │ ├── PartialRoute.java │ │ ├── RangeFactory.java │ │ ├── KeyOrRangeDeps.java │ │ ├── package-info.java │ │ ├── TimestampWithUniqueHlc.java │ │ └── RoutableKey.java │ │ ├── utils │ │ ├── async │ │ │ ├── Cancellable.java │ │ │ └── RunnableWithResult.java │ │ ├── FoldToLong.java │ │ ├── TriConsumer.java │ │ ├── TriFunction.java │ │ ├── TriPredicate.java │ │ ├── BiFoldToLong.java │ │ ├── QuadConsumer.java │ │ ├── QuadFunction.java │ │ ├── IndexedBiFold.java │ │ ├── QuintConsumer.java │ │ ├── TriFoldToLong.java │ │ ├── BiIndexedTriConsumer.java │ │ ├── IndexedTriFold.java │ │ ├── QuadFoldToLong.java │ │ ├── IndexedQuadFunction.java │ │ ├── Reduce.java │ │ ├── SymmetricComparator.java │ │ ├── IndexedRangeQuadFunction.java │ │ ├── AsymmetricComparator.java │ │ ├── IndexedConsumer.java │ │ ├── IndexedFunction.java │ │ ├── MapReduceConsume.java │ │ ├── IndexedPredicate.java │ │ ├── IndexedIntFunction.java │ │ ├── IndexedBiFunction.java │ │ ├── IndexedBiConsumer.java │ │ ├── SortedCursor.java │ │ ├── btree │ │ │ ├── PeekingSearchIterator.java │ │ │ ├── BTreeSearchIterator.java │ │ │ ├── SearchIterator.java │ │ │ └── IndexedSearchIterator.java │ │ ├── IndexedTriConsumer.java │ │ ├── IndexedQuadConsumer.java │ │ ├── IndexedTriFunction.java │ │ ├── DefaultRandom.java │ │ ├── IndexedRangeTriConsumer.java │ │ ├── IndexedRangeQuadConsumer.java │ │ ├── SimpleBitSets.java │ │ ├── SimpleBitSet.java │ │ ├── IndexedFoldToLong.java │ │ ├── IndexedFold.java │ │ ├── IndexedRangeFoldToLong.java │ │ ├── DeterministicIdentitySet.java │ │ ├── IntrusiveLinkedListNode.java │ │ ├── IndexedFoldIntersectToLong.java │ │ ├── UnhandledEnum.java │ │ ├── DebugMap.java │ │ ├── WrapAroundList.java │ │ ├── MapReduce.java │ │ ├── UncheckedInterruptedException.java │ │ ├── random │ │ │ └── Suppliers.java │ │ └── WrapAroundSet.java │ │ ├── local │ │ ├── cfk │ │ │ └── UpdateUnmanagedMode.java │ │ ├── SyncPointListener.java │ │ ├── SequentialAsyncExecutor.java │ │ └── LogUnavailableException.java │ │ ├── topology │ │ ├── ShardSelection.java │ │ ├── SelectTopology.java │ │ ├── TopologyException.java │ │ ├── SelectShards.java │ │ ├── TopologyRetiredException.java │ │ └── TopologyNotReadyException.java │ │ ├── api │ │ ├── AsyncExecutorFactory.java │ │ ├── Sliceable.java │ │ ├── SystemEventListener.java │ │ ├── Result.java │ │ ├── VisibleForImplementationTesting.java │ │ ├── TopologyService.java │ │ ├── VisibleForImplementation.java │ │ ├── Timeouts.java │ │ ├── RoutingKey.java │ │ ├── Key.java │ │ ├── UncaughtExceptionListener.java │ │ ├── Update.java │ │ ├── Query.java │ │ ├── OwnershipEventListener.java │ │ └── BarrierType.java │ │ └── impl │ │ ├── InMemoryAgent.java │ │ ├── SafeState.java │ │ ├── DefaultTimeouts.java │ │ ├── progresslog │ │ ├── Callback.java │ │ ├── TxnStateKind.java │ │ ├── DefaultProgressLogs.java │ │ └── SavedProgressToken.java │ │ ├── AbstractAsyncExecutor.java │ │ └── InMemorySafeCommandsForKey.java │ └── test │ └── java │ └── accord │ ├── utils │ ├── LazyToString.java │ ├── CRCUtilsTest.java │ ├── CRCUtils.java │ └── UtilsTest.java │ ├── verify │ ├── HistoryViolation.java │ └── Verifier.java │ ├── topology │ └── TopologyUtilsTest.java │ ├── impl │ ├── basic │ │ ├── SimulatedFault.java │ │ ├── PendingRunnable.java │ │ └── PendingQueue.java │ └── TopologyFactory.java │ ├── primitives │ └── TxnIdTest.java │ ├── burn │ ├── random │ │ └── IntRange.java │ └── SimulationException.java │ └── coordinate │ └── FailureAccumulatorTest.java ├── .build └── checkstyle │ ├── suppressions.xml │ └── checkstyle.xml ├── gradle.properties ├── .asf.yaml └── accord-maelstrom ├── src └── main │ └── java │ └── accord │ └── maelstrom │ ├── Wrapper.java │ ├── MaelstromReplyContext.java │ ├── MaelstromData.java │ ├── MaelstromInit.java │ ├── SimpleTopologyService.java │ ├── Error.java │ └── MaelstromWrite.java └── build.gradle /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/cassandra-accord/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Apache Cassandra Accord 2 | Copyright 2021- The Apache Software Foundation 3 | 4 | This product includes software developed by The Apache Software 5 | Foundation (http://www.apache.org/). 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .gradle/ 3 | build/ 4 | accord-core/build/ 5 | accord-maelstrom/build/ 6 | .rat-excludes.txt 7 | 8 | # Coding tools like NeoVim and Visual Studio Code will store their metadata at the following paths 9 | accord-core/bin/ 10 | accord-maelstrom/bin/ 11 | .project 12 | .settings 13 | .classpath 14 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | rootProject.name = 'accord' 20 | include 'accord-core' 21 | include 'accord-maelstrom' 22 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/coordinate/StaleTopology.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.coordinate; 20 | 21 | public class StaleTopology extends Exception 22 | { 23 | } 24 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/messages/Message.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.messages; 20 | 21 | public interface Message 22 | { 23 | MessageType type(); 24 | } 25 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/primitives/WithQuorum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.primitives; 20 | 21 | public enum WithQuorum 22 | { 23 | HasQuorum, NoQuorum 24 | } 25 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/async/Cancellable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils.async; 20 | 21 | public interface Cancellable 22 | { 23 | void cancel(); 24 | } 25 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/FoldToLong.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface FoldToLong 22 | { 23 | long apply(P1 p1, long accumulate); 24 | } 25 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/TriConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package accord.utils; 19 | 20 | public interface TriConsumer 21 | { 22 | void accept(P1 p1, P2 p2, P3 p3); 23 | } 24 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/coordinate/ExecutePath.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.coordinate; 20 | 21 | public enum ExecutePath 22 | { 23 | EPHEMERAL, FAST, MEDIUM, SLOW, RECOVER 24 | } 25 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/TriFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface TriFunction 22 | { 23 | O apply(P1 p1, P2 p2, P3 p3); 24 | } 25 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/local/cfk/UpdateUnmanagedMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.local.cfk; 20 | 21 | public enum UpdateUnmanagedMode 22 | { 23 | REGISTER_DEPS_ONLY, REGISTER, UPDATE 24 | } -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/messages/ReplyContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.messages; 20 | 21 | // TODO: rename to ExecutionContext maybe? 22 | public interface ReplyContext 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/topology/ShardSelection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.topology; 20 | 21 | import java.util.BitSet; 22 | 23 | public class ShardSelection extends BitSet 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/TriPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface TriPredicate 22 | { 23 | boolean test(P1 p1, P2 p2, P3 p3); 24 | } 25 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/BiFoldToLong.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface BiFoldToLong 22 | { 23 | long apply(P1 p1, P2 p2, long accumulate); 24 | } 25 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/QuadConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package accord.utils; 19 | 20 | public interface QuadConsumer 21 | { 22 | void accept(P1 p1, P2 p2, P3 p3, P4 p4); 23 | } 24 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/QuadFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface QuadFunction 22 | { 23 | O apply(P1 p1, P2 p2, P3 p3, P4 p4); 24 | } 25 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/local/SyncPointListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.local; 20 | 21 | public interface SyncPointListener 22 | { 23 | void update(SafeCommandStore safeStore, Command command); 24 | } 25 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedBiFold.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedBiFold extends IndexedTriFunction 22 | { 23 | } -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/QuintConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package accord.utils; 19 | 20 | public interface QuintConsumer 21 | { 22 | void accept(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5); 23 | } 24 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/TriFoldToLong.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface TriFoldToLong 22 | { 23 | long apply(P1 p1, P2 p2, P3 p3, long accumulate); 24 | } 25 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/BiIndexedTriConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface BiIndexedTriConsumer 22 | { 23 | void accept(P1 p1, P2 p2, P3 p3, int i1, int i2); 24 | } 25 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedTriFold.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedTriFold extends IndexedQuadFunction 22 | { 23 | } -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/QuadFoldToLong.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface QuadFoldToLong 22 | { 23 | long apply(P1 p1, P2 p2, P3 p3, P4 p4, long accumulate); 24 | } 25 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedQuadFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedQuadFunction 22 | { 23 | V apply(P1 p1, P2 p2, P3 p3, P4 p4, int index); 24 | } 25 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/coordinate/Outcome.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.coordinate; 20 | 21 | import accord.primitives.ProgressToken; 22 | 23 | public interface Outcome 24 | { 25 | ProgressToken asProgressToken(); 26 | } 27 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/Reduce.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface Reduce 22 | { 23 | static Reduce toNull() { return (a, b) -> null; } 24 | O reduce(O o1, I o2); 25 | } 26 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/SymmetricComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | import java.util.Comparator; 22 | 23 | public interface SymmetricComparator extends AsymmetricComparator, Comparator 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /.build/checkstyle/suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedRangeQuadFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedRangeQuadFunction 22 | { 23 | V apply(P1 p1, P2 p2, P3 p3, P4 p4, int startIndex, int endIndex); 24 | } 25 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/local/SequentialAsyncExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.local; 20 | 21 | import accord.api.AsyncExecutor; 22 | 23 | /** 24 | * A single-threaded AsyncExecutor 25 | */ 26 | public interface SequentialAsyncExecutor extends AsyncExecutor 27 | { 28 | } 29 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/primitives/EpochSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.primitives; 20 | 21 | public interface EpochSupplier 22 | { 23 | long epoch(); 24 | 25 | static EpochSupplier constant(long epoch) 26 | { 27 | return () -> epoch; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/primitives/FullRoute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.primitives; 20 | 21 | public interface FullRoute extends Route, Unseekables 22 | { 23 | @Override default FullRoute with(Participants route) { return this; } 24 | } 25 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/topology/SelectTopology.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.topology; 20 | 21 | import accord.primitives.Unseekables; 22 | 23 | public interface SelectTopology 24 | { 25 | Topology apply(Topology topology, Unseekables select) throws TopologyException; 26 | } 27 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/api/AsyncExecutorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.api; 20 | 21 | import accord.local.SequentialAsyncExecutor; 22 | 23 | public interface AsyncExecutorFactory 24 | { 25 | AsyncExecutor someExecutor(); 26 | SequentialAsyncExecutor someSequentialExecutor(); 27 | } 28 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/impl/InMemoryAgent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.impl; 20 | 21 | import accord.api.Agent; 22 | import accord.utils.async.AsyncResult; 23 | 24 | public interface InMemoryAgent extends Agent 25 | { 26 | AsyncResult snapshot(InMemoryCommandStore commandStore); 27 | } 28 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/AsymmetricComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | // similar to Cassandra's AsymmetricOrdering, only we can create a static lambda function of this 22 | public interface AsymmetricComparator 23 | { 24 | int compare(T1 t1, T2 t2); 25 | } 26 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/coordinate/tracking/ResponseTracker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.coordinate.tracking; 20 | 21 | import accord.local.Node; 22 | 23 | public interface ResponseTracker 24 | { 25 | RequestStatus recordSuccess(Node.Id node); 26 | RequestStatus recordFailure(Node.Id node); 27 | } 28 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedConsumer 22 | { 23 | /** 24 | * Apply some consumer to an object parameter and an associated index (usually within a collection). 25 | */ 26 | void accept(P1 p1, int index); 27 | } 28 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedFunction 22 | { 23 | /** 24 | * Apply some function to an object parameter and an associated index (usually within a collection). 25 | */ 26 | O apply(P1 p1, int index); 27 | } 28 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/MapReduceConsume.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | import java.util.function.BiConsumer; 22 | 23 | public interface MapReduceConsume extends MapReduce, BiConsumer 24 | { 25 | @Override 26 | void accept(O result, Throwable failure); 27 | } 28 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedPredicate 22 | { 23 | /** 24 | * Apply some predicate to an object parameter and an associated index (usually within a collection). 25 | */ 26 | boolean test(P1 p1, int index); 27 | } 28 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedIntFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedIntFunction 22 | { 23 | /** 24 | * Apply some function to an int parameter and an associated index (usually within a collection). 25 | */ 26 | int apply(P1 p1, int p2, int index); 27 | } 28 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedBiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedBiFunction 22 | { 23 | /** 24 | * Apply some function to two object parameters and an associated index (usually within a collection). 25 | */ 26 | O apply(P1 p1, P2 p2, int index); 27 | } 28 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/impl/SafeState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.impl; 20 | 21 | /** 22 | * State scoped to a single request that references global state 23 | */ 24 | public interface SafeState 25 | { 26 | T current(); 27 | 28 | default boolean isUnset() 29 | { 30 | return current() == null; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedBiConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedBiConsumer 22 | { 23 | /** 24 | * Apply some function to two object parameters and an associated index (usually within a collection). 25 | */ 26 | void accept(P1 p1, P2 p2, int index); 27 | } 28 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/primitives/Unseekable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.primitives; 20 | 21 | import accord.api.RoutingKey; 22 | 23 | /** 24 | * Something that can only be routed, i.e. is NOT a Seekable. 25 | */ 26 | public interface Unseekable extends Routable 27 | { 28 | Range asRange(); 29 | RoutingKey asRoutingKey(); 30 | } 31 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/api/Sliceable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.api; 20 | 21 | import accord.primitives.Participants; 22 | import accord.primitives.Ranges; 23 | 24 | public interface Sliceable> 25 | { 26 | T slice(Ranges ranges); 27 | T intersecting(Participants participants); 28 | T merge(T merge); 29 | } 30 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/api/SystemEventListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.api; 20 | 21 | public interface SystemEventListener 22 | { 23 | default void onWaitingForEpoch(long epoch) {} 24 | default void onTimeoutForEpoch(long epoch, int count) {} 25 | 26 | SystemEventListener NOOP = new SystemEventListener() 27 | { 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/impl/DefaultTimeouts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.impl; 20 | 21 | import accord.local.TimeService; 22 | 23 | public class DefaultTimeouts extends AbstractTimeouts 24 | { 25 | public DefaultTimeouts(TimeService time) 26 | { 27 | super(time, Stripe[]::new, Stripe::new); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | accord_group=accord 18 | accord_artifactId=accord 19 | accord_version=1.0-SNAPSHOT 20 | 21 | # Some times there are ephemeral issues with fetching dependencies (namely Rat) in CI, so this bumps the timeout to 120s to try to make it more stable 22 | systemProp.org.gradle.internal.http.connectionTimeout=120000 23 | systemProp.org.gradle.internal.http.socketTimeout=120000 24 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/coordinate/tracking/RequestStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.coordinate.tracking; 20 | 21 | public enum RequestStatus 22 | { 23 | Failed, 24 | Success, 25 | NoChange; 26 | 27 | public static RequestStatus min(RequestStatus a, RequestStatus b) 28 | { 29 | return a.compareTo(b) <= 0 ? a : b; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/SortedCursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package accord.utils; 19 | 20 | public interface SortedCursor> 21 | { 22 | // move to the first item >= find, returning true if an exact match was found 23 | boolean find(Comparable find); 24 | void advance(); 25 | boolean hasCur(); 26 | T cur(); 27 | } 28 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/btree/PeekingSearchIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package accord.utils.btree; 19 | 20 | public interface PeekingSearchIterator extends SearchIterator 21 | { 22 | /** 23 | * @return true if iterator has any elements left, false otherwise 24 | */ 25 | boolean hasNext(); 26 | 27 | V next(); 28 | 29 | V peek(); 30 | } 31 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/btree/BTreeSearchIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package accord.utils.btree; 20 | 21 | import java.util.Iterator; 22 | 23 | public interface BTreeSearchIterator extends IndexedSearchIterator, Iterator, PeekingSearchIterator 24 | { 25 | /** 26 | * Reset this Iterator to its starting position 27 | */ 28 | public void rewind(); 29 | } 30 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/primitives/Seekable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.primitives; 20 | 21 | import accord.api.Key; 22 | 23 | /** 24 | * Something that can be found within the cluster AND found on disk, queried and returned 25 | */ 26 | public interface Seekable extends Routable 27 | { 28 | Key asKey(); 29 | Range asRange(); 30 | Seekable slice(Range range); 31 | } 32 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/coordinate/tracking/ShardTracker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.coordinate.tracking; 20 | 21 | import accord.topology.Shard; 22 | 23 | public abstract class ShardTracker 24 | { 25 | public final Shard shard; 26 | 27 | public ShardTracker(Shard shard) 28 | { 29 | this.shard = shard; 30 | } 31 | 32 | public abstract String summarise(); 33 | } 34 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | distributionBase=GRADLE_USER_HOME 18 | distributionPath=wrapper/dists 19 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip 20 | # Some CI environments have ephemeral issues fetching the gradle runtime, so increased the timeout from the default 10s to 60s to make it more stable 21 | networkTimeout=60000 22 | zipStoreBase=GRADLE_USER_HOME 23 | zipStorePath=wrapper/dists 24 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/primitives/PartialRoute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.primitives; 20 | 21 | public interface PartialRoute extends Route 22 | { 23 | @Override 24 | boolean isEmpty(); 25 | 26 | /** 27 | * Expected to be compatible PartialRoute type, i.e. both split from the same FullRoute 28 | */ 29 | PartialRoute with(PartialRoute route); 30 | } 31 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/impl/progresslog/Callback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.impl.progresslog; 20 | 21 | import accord.local.SafeCommand; 22 | import accord.local.SafeCommandStore; 23 | import accord.primitives.TxnId; 24 | 25 | interface Callback 26 | { 27 | void callback(SafeCommandStore safeStore, SafeCommand safeCommand, DefaultProgressLog instance, TxnId txnId, P param, V success, Throwable fail); 28 | } 29 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/topology/TopologyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.topology; 20 | 21 | import accord.utils.Rethrowable; 22 | 23 | public abstract class TopologyException extends Exception implements Rethrowable 24 | { 25 | public TopologyException(String message) { super(message); } 26 | public TopologyException(String message, Throwable cause) { super(message, cause); } 27 | } 28 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/api/Result.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.api; 20 | 21 | import accord.coordinate.Outcome; 22 | import accord.primitives.ProgressToken; 23 | 24 | /** 25 | * A result to be returned to a client, or be stored in a node's command state. 26 | */ 27 | public interface Result extends Outcome 28 | { 29 | @Override 30 | default ProgressToken asProgressToken() { return ProgressToken.APPLIED; } 31 | } 32 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/api/VisibleForImplementationTesting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.api; 20 | 21 | import java.lang.annotation.Documented; 22 | import java.lang.annotation.Inherited; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | 26 | @Documented 27 | @Inherited 28 | @Retention(RetentionPolicy.SOURCE) 29 | public @interface VisibleForImplementationTesting 30 | { 31 | } 32 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/impl/progresslog/TxnStateKind.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.impl.progresslog; 20 | 21 | /** 22 | * The kinds of TxnState we support in the DefaultProgressLog. This is used to manage timers and other shared state. 23 | */ 24 | public enum TxnStateKind 25 | { 26 | Waiting, Home; 27 | 28 | TxnStateKind other() 29 | { 30 | return this == Waiting ? Home : Waiting; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/messages/Request.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.messages; 20 | 21 | import accord.local.Node; 22 | import accord.local.Node.Id; 23 | import accord.primitives.TxnId; 24 | 25 | public interface Request extends Message 26 | { 27 | default long waitForEpoch() { return 0; } 28 | void process(Node on, Id from, ReplyContext replyContext); 29 | default TxnId primaryTxnId() { return null; } 30 | } 31 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/topology/SelectShards.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.topology; 20 | 21 | public enum SelectShards 22 | { 23 | /** 24 | * Select from all shards including those being removed (used only for sync points) 25 | */ 26 | ALL, 27 | 28 | /** 29 | * Limit selection to live shards (i.e. throw TopologyException if some requested keys are marked for removal) 30 | */ 31 | LIVE 32 | } 33 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/messages/SimpleReply.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.messages; 20 | 21 | public enum SimpleReply implements Reply 22 | { 23 | Ok, Nack; 24 | 25 | public SimpleReply merge(SimpleReply that) 26 | { 27 | return this == that ? this : Nack; 28 | } 29 | 30 | @Override 31 | public MessageType type() 32 | { 33 | return MessageType.StandardMessage.SIMPLE_RSP; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/api/TopologyService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.api; 20 | 21 | import accord.local.Node; 22 | import accord.topology.Topology; 23 | import accord.utils.async.AsyncResult; 24 | 25 | /** 26 | * API for fetching topologies associated with a given epoch 27 | */ 28 | public interface TopologyService 29 | { 30 | AsyncResult fetchTopologyForEpoch(long epoch); 31 | default void onStartup(Node node) {} 32 | } 33 | -------------------------------------------------------------------------------- /accord-core/src/test/java/accord/utils/LazyToString.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | import java.util.function.Supplier; 22 | 23 | public class LazyToString 24 | { 25 | private final Supplier toString; 26 | 27 | public LazyToString(Supplier toString) 28 | { 29 | this.toString = toString; 30 | } 31 | 32 | @Override 33 | public String toString() 34 | { 35 | return this.toString.get(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/coordinate/tracking/ShardOutcome.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.coordinate.tracking; 20 | 21 | /** 22 | * Represents the logical result of a ShardFunction applied to a ShardTracker, 23 | * encapsulating also any modification it should make to the AbstractTracker 24 | * containing the shard. 25 | */ 26 | public interface ShardOutcome> 27 | { 28 | AbstractTracker.ShardOutcomes apply(T tracker, int shardIndex); 29 | } 30 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedTriConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedTriConsumer 22 | { 23 | /** 24 | * Consume some object parameters associated with an index in a collection. 25 | * 26 | * The first parameter is typically used to convey some container the index refer to, 27 | * with the others providing other configuration. 28 | */ 29 | void accept(P1 p1, P2 p2, P3 p3, int index); 30 | } 31 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedQuadConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedQuadConsumer 22 | { 23 | /** 24 | * Consume some object parameters associated with an index in a collection. 25 | * 26 | * The last parameter is typically used to convey some container the index refer to, 27 | * with the others providing other configuration. 28 | */ 29 | void accept(P1 p1, P2 p2, P3 p3, P4 p4, int index); 30 | } 31 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedTriFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedTriFunction 22 | { 23 | /** 24 | * Apply a function to some object parameters associated with an index in a collection. 25 | * 26 | * The first parameter is typically used to convey some container the index refer to, 27 | * with the others providing other configuration. 28 | */ 29 | V apply(P1 p1, P2 p2, P3 p3, int index); 30 | } 31 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/primitives/RangeFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.primitives; 20 | 21 | import accord.api.RoutingKey; 22 | 23 | public interface RangeFactory 24 | { 25 | Range newRange(RoutingKey start, RoutingKey end); 26 | // makes a range representing a lack of knowledge that is used for e.g. subtracting from another range; weaker invariant checks may therefore apply 27 | default Range newAntiRange(RoutingKey start, RoutingKey end) { return newRange(start, end); } 28 | } 29 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/DefaultRandom.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | import java.util.Random; 22 | 23 | public class DefaultRandom extends WrappedRandomSource 24 | { 25 | public DefaultRandom() 26 | { 27 | super(new Random()); 28 | } 29 | 30 | public DefaultRandom(long seed) 31 | { 32 | super(new Random(seed)); 33 | } 34 | 35 | @Override 36 | public DefaultRandom fork() { 37 | return new DefaultRandom(nextLong()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedRangeTriConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedRangeTriConsumer 22 | { 23 | /** 24 | * Consume some object parameters associated with a range of indexes from a collection. 25 | * 26 | * The first parameter is typically used to convey some container the indexes refer to, 27 | * with the others providing other configuration. 28 | */ 29 | void accept(P1 p1, P2 p2, P3 p3, int fromIndex, int toIndex); 30 | } 31 | -------------------------------------------------------------------------------- /.asf.yaml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | notifications: 19 | commits: commits@cassandra.apache.org 20 | issues: commits@cassandra.apache.org 21 | pullrequests: pr@cassandra.apache.org 22 | jira_options: link worklog 23 | 24 | github: 25 | description: "Accord library for Apache Cassandra®" 26 | homepage: https://cassandra.apache.org/ 27 | enabled_merge_buttons: 28 | squash: true 29 | merge: false 30 | rebase: true 31 | features: 32 | wiki: false 33 | issues: false 34 | projects: false 35 | autolink_jira: 36 | - CASSANDRA 37 | -------------------------------------------------------------------------------- /accord-core/src/test/java/accord/verify/HistoryViolation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.verify; 20 | 21 | public class HistoryViolation extends AssertionError 22 | { 23 | final String prefix; 24 | final int primaryKey; 25 | 26 | public HistoryViolation(String prefix, int primaryKey, Object detailMessage) 27 | { 28 | super(detailMessage); 29 | this.prefix = prefix; 30 | this.primaryKey = primaryKey; 31 | } 32 | 33 | public int primaryKey() { 34 | return primaryKey; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/api/VisibleForImplementation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.api; 20 | 21 | import java.lang.annotation.Documented; 22 | import java.lang.annotation.Inherited; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | 26 | /** 27 | * Indicates an element exists or is more visible than otherwise needed to support implementations 28 | */ 29 | @Documented 30 | @Inherited 31 | @Retention(RetentionPolicy.SOURCE) 32 | public @interface VisibleForImplementation 33 | { 34 | } 35 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedRangeQuadConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedRangeQuadConsumer 22 | { 23 | /** 24 | * Consume some object parameters associated with a range of indexes from a collection. 25 | * 26 | * The first parameter is typically used to convey some container the indexes refer to, 27 | * with the others providing other configuration. 28 | */ 29 | void accept(P1 p1, P2 p2, P3 p3, P4 p4, int fromIndex, int toIndex); 30 | } 31 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/SimpleBitSets.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public final class SimpleBitSets 22 | { 23 | private SimpleBitSets() {} 24 | 25 | public static SimpleBitSet allSet(int bits) 26 | { 27 | SimpleBitSet set = SimpleBitSet.allocate(bits); 28 | for (int i = 0; i < bits; i++) 29 | set.set(i); 30 | return set; 31 | } 32 | 33 | public static SimpleBitSet allUnset(int bits) 34 | { 35 | return SimpleBitSet.allocate(bits); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/primitives/KeyOrRangeDeps.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.primitives; 20 | 21 | import accord.utils.SortedArrays; 22 | 23 | public interface KeyOrRangeDeps 24 | { 25 | Participants participants(TxnId txnId); 26 | Participants participants(int indexOf); 27 | TxnId txnId(int indexOf); 28 | TxnId txnIdWithFlags(int indexOf); 29 | int txnIdCount(); 30 | SortedArrays.SortedArrayList txnIdsWithFlags(); 31 | boolean intersects(TxnId txnId, Ranges ranges); 32 | boolean contains(TxnId txnId); 33 | } 34 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/SimpleBitSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface SimpleBitSet 22 | { 23 | boolean get(int i); 24 | boolean set(int i); 25 | void setRange(int from, int to); 26 | boolean unset(int i); 27 | void clear(); 28 | boolean isEmpty(); 29 | int nextSetBit(int fromIndex); 30 | int getSetBitCount(); 31 | 32 | static SimpleBitSet allocate(int size) 33 | { 34 | if (size <= 64) return new SmallBitSet(); 35 | else return new LargeBitSet(size); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /accord-core/src/test/java/accord/topology/TopologyUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.topology; 20 | 21 | import org.junit.jupiter.api.Assertions; 22 | import org.junit.jupiter.api.Test; 23 | 24 | import static accord.Utils.ranges; 25 | import static accord.impl.IntKey.range; 26 | 27 | public class TopologyUtilsTest 28 | { 29 | @Test 30 | void initialRangesTest() 31 | { 32 | Assertions.assertEquals(ranges(range(0, 100), range(100, 200), range(200, 300)), 33 | TopologyUtils.initialRanges(3, 300)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/api/Timeouts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.api; 20 | 21 | import java.util.concurrent.TimeUnit; 22 | 23 | import accord.utils.async.Cancellable; 24 | 25 | public interface Timeouts 26 | { 27 | interface Timeout 28 | { 29 | void timeout(); 30 | int stripe(); 31 | } 32 | 33 | interface RegisteredTimeout extends Cancellable 34 | { 35 | @Override 36 | void cancel(); 37 | } 38 | 39 | RegisteredTimeout registerAt(Timeout timeout, long deadline, TimeUnit units); 40 | void maybeNotify(); 41 | } 42 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/coordinate/tracking/PreAcceptExclusiveSyncPointTracker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.coordinate.tracking; 20 | 21 | import accord.primitives.TxnId; 22 | import accord.topology.Topologies; 23 | 24 | public class PreAcceptExclusiveSyncPointTracker extends QuorumTracker 25 | { 26 | public PreAcceptExclusiveSyncPointTracker(Topologies topologies, TxnId txnId) 27 | { 28 | super(topologies); 29 | } 30 | 31 | @Override 32 | public boolean hasMediumPathAccepted() 33 | { 34 | return hasReachedQuorum(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/local/LogUnavailableException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.local; 20 | 21 | import accord.utils.Rethrowable; 22 | 23 | public class LogUnavailableException extends RuntimeException implements Rethrowable 24 | { 25 | public LogUnavailableException() 26 | { 27 | } 28 | 29 | private LogUnavailableException(Throwable cause) 30 | { 31 | super(cause); 32 | } 33 | 34 | @Override 35 | public LogUnavailableException rethrowable() 36 | { 37 | return new LogUnavailableException(this); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /accord-core/src/test/java/accord/verify/Verifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.verify; 20 | 21 | public interface Verifier extends AutoCloseable 22 | { 23 | default Checker witness(int start, int end) { return witness("", start, end); } 24 | 25 | Checker witness(Object description, int start, int end); 26 | 27 | interface Checker extends AutoCloseable 28 | { 29 | void read(int index, int[] seq); 30 | void write(int index, int value); 31 | 32 | @Override 33 | default void close() {} 34 | } 35 | 36 | @Override 37 | default void close() {} 38 | } 39 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/api/RoutingKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.api; 20 | 21 | import accord.primitives.Range; 22 | import accord.primitives.RangeFactory; 23 | import accord.primitives.RoutableKey; 24 | import accord.primitives.Unseekable; 25 | 26 | public interface RoutingKey extends Unseekable, RoutableKey 27 | { 28 | @Override default RoutingKey toUnseekable() { return this; } 29 | @Override default RoutingKey asRoutingKey() { return this; } 30 | @Override default Kind kind() { return Kind.UnseekableKey; } 31 | 32 | Range asRange(); 33 | RangeFactory rangeFactory(); 34 | } 35 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedFoldToLong.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedFoldToLong 22 | { 23 | /** 24 | * Apply some long->long merge function accepting a constant object parameter p1, a constant long parameter p2, 25 | * and the prior output of this function or the initial value, to some element of a collection, 26 | * with the index of the element provided. 27 | * 28 | * This function is used for efficiently folding over some subset of a collection. 29 | */ 30 | long apply(P1 p1, long p2, long accumulate, int index); 31 | } 32 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/impl/progresslog/DefaultProgressLogs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.impl.progresslog; 20 | 21 | import accord.api.ProgressLog; 22 | import accord.local.CommandStore; 23 | import accord.local.Node; 24 | 25 | public class DefaultProgressLogs implements ProgressLog.Factory 26 | { 27 | protected final Node node; 28 | 29 | public DefaultProgressLogs(Node node) 30 | { 31 | this.node = node; 32 | } 33 | 34 | @Override 35 | public DefaultProgressLog create(CommandStore commandStore) 36 | { 37 | return new DefaultProgressLog(node, commandStore); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedFold.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedFold extends IndexedBiFunction 22 | { 23 | /** 24 | * Apply some merge function accepting a constant object parameter p1, and the prior output of this function 25 | * or the initial value, to some element of a collection, with the index of the element provided. 26 | * 27 | * This function is used for efficiently folding over some subset of a collection. 28 | */ 29 | @Override 30 | Accumulate apply(P1 p1, Accumulate p2, int index); 31 | } -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/impl/progresslog/SavedProgressToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.impl.progresslog; 20 | 21 | import accord.primitives.ProgressToken; 22 | import accord.primitives.TxnId; 23 | 24 | class SavedProgressToken extends ProgressToken 25 | { 26 | final TxnId txnId; 27 | 28 | public SavedProgressToken(TxnId txnId, ProgressToken copy) 29 | { 30 | super(copy.outcome, copy.status, copy.promised, copy.isAccepted); 31 | this.txnId = txnId; 32 | } 33 | 34 | public int compare(SavedProgressToken that) 35 | { 36 | return this.txnId.compareTo(that.txnId); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedRangeFoldToLong.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedRangeFoldToLong 22 | { 23 | /** 24 | * Apply some long->long merge function accepting a constant parameter p1 and the prior output of this 25 | * function or an initial value, to some range of indexes referencing some other indexed collection. 26 | * 27 | * This function is used for folding over a filtered collection, where contiguous ranges are expected 28 | * and can be handled batch-wise. 29 | */ 30 | long apply(long p1, long accumulator, int fromIndex, int toIndex); 31 | } -------------------------------------------------------------------------------- /accord-core/src/test/java/accord/impl/basic/SimulatedFault.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.impl.basic; 20 | 21 | import accord.utils.Rethrowable; 22 | 23 | public class SimulatedFault extends AssertionError implements Rethrowable 24 | { 25 | public SimulatedFault(Object detailMessage) 26 | { 27 | super(detailMessage); 28 | } 29 | 30 | public SimulatedFault(String message, Throwable cause) 31 | { 32 | super(message, cause); 33 | } 34 | 35 | @Override 36 | public SimulatedFault rethrowable() 37 | { 38 | return new SimulatedFault(getMessage(), this); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /accord-core/src/test/java/accord/primitives/TxnIdTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.primitives; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import accord.utils.AccordGens; 24 | import org.assertj.core.api.Assertions; 25 | 26 | import static accord.utils.Property.qt; 27 | 28 | class TxnIdTest 29 | { 30 | @Test 31 | void stringSerde() 32 | { 33 | qt().forAll(AccordGens.txnIds()).check(id -> { 34 | Assertions.assertThat(TxnId.parse(id.toString())).isEqualTo(id); 35 | 36 | Assertions.assertThat(Timestamp.fromString(id.toStandardString())).isEqualTo(new Timestamp(id)); 37 | }); 38 | } 39 | } -------------------------------------------------------------------------------- /accord-core/src/test/java/accord/impl/basic/PendingRunnable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.impl.basic; 20 | 21 | public interface PendingRunnable extends Pending, Runnable 22 | { 23 | static PendingRunnable create(Runnable run) 24 | { 25 | Pending origin = Global.activeOrigin(); 26 | return new PendingRunnable() 27 | { 28 | @Override 29 | public Pending origin() 30 | { 31 | return origin; 32 | } 33 | 34 | @Override 35 | public void run() 36 | { 37 | run.run(); 38 | } 39 | }; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /.build/checkstyle/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/api/Key.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.api; 20 | 21 | import accord.primitives.Range; 22 | import accord.primitives.RoutableKey; 23 | import accord.primitives.Seekable; 24 | 25 | /** 26 | * A key we can find in both the cluster and on disk 27 | */ 28 | public interface Key extends Seekable, RoutableKey 29 | { 30 | @Override 31 | default Key asKey() { return this; } 32 | 33 | @Override 34 | default Key slice(Range range) { return this; } 35 | 36 | @Override 37 | default Range asRange() { throw new UnsupportedOperationException(); } 38 | 39 | @Override 40 | default Kind kind() { return Kind.SeekableKey; } 41 | } 42 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/messages/Callback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.messages; 20 | 21 | import javax.annotation.Nullable; 22 | 23 | import accord.local.Node.Id; 24 | 25 | /** 26 | * Represents some execution for handling responses from messages a node has sent. 27 | */ 28 | public interface Callback 29 | { 30 | void onSuccess(Id from, T reply); 31 | default void onSlowResponse(Id from) {} 32 | // null to be interpreted as Timeout 33 | void onFailure(Id from, @Nullable Throwable failure); 34 | // return true if the failure was handled/propagated 35 | default boolean onCallbackFailure(Id from, Throwable failure) { return false; } 36 | } 37 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/DeterministicIdentitySet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | import java.util.*; 22 | 23 | // LinkedHashSet isn't always suitable, due to ConcurrentModificationException 24 | public class DeterministicIdentitySet extends DeterministicSet 25 | { 26 | public DeterministicIdentitySet() 27 | { 28 | this(0); 29 | } 30 | 31 | public DeterministicIdentitySet(int size) 32 | { 33 | super(new IdentityHashMap<>(size)); 34 | } 35 | 36 | public DeterministicIdentitySet(DeterministicIdentitySet copy) 37 | { 38 | this(copy.size()); 39 | copy.forEach(this::addInternal); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IntrusiveLinkedListNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | /** 22 | * TODO (low priority): COPIED FROM CASSANDRA 23 | */ 24 | public abstract class IntrusiveLinkedListNode 25 | { 26 | IntrusiveLinkedListNode prev; 27 | IntrusiveLinkedListNode next; 28 | 29 | protected boolean isFree() 30 | { 31 | return next == null; 32 | } 33 | 34 | protected void remove() 35 | { 36 | if (next != null) 37 | { 38 | prev.next = next; 39 | next.prev = prev; 40 | next = null; 41 | prev = null; 42 | } 43 | Invariants.paranoid(prev == null); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/IndexedFoldIntersectToLong.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public interface IndexedFoldIntersectToLong 22 | { 23 | /** 24 | * Apply some long->long merge function accepting a constant object parameter p1, a long parameter p2, and the prior 25 | * output of this function or the initial value, to some element occurring in two collections, with each collection's 26 | * index for the element provided as the final parameters. 27 | * 28 | * This function is used for folding over the common elements of two sorted collections. 29 | */ 30 | long apply(P1 p1, long p2, long accumulate, int leftIndex, int rightIndex); 31 | } 32 | -------------------------------------------------------------------------------- /accord-maelstrom/src/main/java/accord/maelstrom/Wrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.maelstrom; 20 | 21 | import java.io.IOException; 22 | 23 | import com.google.gson.stream.JsonWriter; 24 | import accord.maelstrom.Packet.Type; 25 | 26 | public class Wrapper extends Body 27 | { 28 | final Object body; 29 | 30 | public Wrapper(Type type, long msg_id, long in_reply_to, Object body) 31 | { 32 | super(type, msg_id, in_reply_to); 33 | this.body = body; 34 | } 35 | 36 | @Override 37 | void writeBody(JsonWriter out) throws IOException 38 | { 39 | super.writeBody(out); 40 | out.name("body"); 41 | Json.GSON.toJson(body, type.type, out); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/async/RunnableWithResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils.async; 20 | 21 | import java.util.concurrent.Callable; 22 | 23 | public class RunnableWithResult implements Callable 24 | { 25 | final Runnable run; 26 | final V result; 27 | 28 | public RunnableWithResult(Runnable run, V result) 29 | { 30 | this.run = run; 31 | this.result = result; 32 | } 33 | 34 | @Override 35 | public V call() throws Exception 36 | { 37 | run.run(); 38 | return result; 39 | } 40 | 41 | @Override 42 | public String toString() 43 | { 44 | return "[Run " + run.toString() + "; return " + result + ']'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /accord-core/src/test/java/accord/utils/CRCUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import org.assertj.core.api.Assertions; 24 | 25 | import static accord.utils.CRCUtils.crc32LittleEnding; 26 | import static accord.utils.CRCUtils.reverseCRC32LittleEnding; 27 | import static accord.utils.Property.qt; 28 | 29 | class CRCUtilsTest 30 | { 31 | @Test 32 | void backAndForth() 33 | { 34 | qt().withExamples(100_000).forAll(Gens.ints().all()).check(key -> { 35 | int hash = crc32LittleEnding(key); 36 | int unhash = reverseCRC32LittleEnding(hash); 37 | Assertions.assertThat(unhash).isEqualTo(key); 38 | }); 39 | } 40 | } -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/btree/SearchIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package accord.utils.btree; 19 | 20 | public interface SearchIterator 21 | { 22 | /** 23 | * Searches "forwards" (in direction of travel) in the iterator for the required key; 24 | * if this or any key greater has already been returned by the iterator, the method may 25 | * choose to return null, the correct or incorrect output, or fail an assertion. 26 | * 27 | * it is permitted to search past the end of the iterator, i.e. {@code !hasNext() => next(?) == null} 28 | * 29 | * @param key to search for 30 | * @return value associated with key, if present in direction of travel 31 | */ 32 | public V next(K key); 33 | } 34 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/primitives/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.primitives; 20 | 21 | /** 22 | * Routable: a RoutingKey, Key or Range. Something that can address a replica in the cluster. 23 | * Unseekable: a RoutingKey or Range (of RoutingKey). Something that can ONLY address a replica in the cluster. 24 | * Seekable: a Key or Range (of either RoutingKey or Key). Something that can address some physical data on a node. 25 | * Routables: a collection of Routable 26 | * Unseekables: a collection of Unseekable 27 | * Seekables: a collection of Seekable 28 | * Route: a collection of Routable including a homeKey. Represents a consistent slice (or slices) of token ranges. 29 | * Either a PartialRoute or a FullRoute. 30 | */ 31 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/btree/IndexedSearchIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package accord.utils.btree; 19 | 20 | public interface IndexedSearchIterator extends SearchIterator 21 | { 22 | /** 23 | * @return true if iterator has any elements left, false otherwise 24 | */ 25 | public boolean hasNext(); 26 | 27 | /** 28 | * @return the value just recently returned by next() 29 | * @throws java.util.NoSuchElementException if next() returned null 30 | */ 31 | public V current(); 32 | 33 | /** 34 | * @return the index of the value returned by current(), and just returned by next() 35 | * @throws java.util.NoSuchElementException if next() returned null 36 | */ 37 | public int indexOfCurrent(); 38 | } 39 | -------------------------------------------------------------------------------- /accord-core/src/test/java/accord/burn/random/IntRange.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.burn.random; 20 | 21 | import accord.utils.Gen; 22 | import accord.utils.RandomSource; 23 | 24 | public class IntRange implements Gen.LongGen 25 | { 26 | public final int min, max; 27 | private final int maxDelta; 28 | 29 | public IntRange(int min, int max) 30 | { 31 | if (min >= max) throw new IllegalArgumentException(String.format("Min (%s) should be less than max (%d).", min, max)); 32 | this.min = min; 33 | this.max = max; 34 | this.maxDelta = max - min + 1; 35 | } 36 | 37 | @Override 38 | public long nextLong(RandomSource randomSource) 39 | { 40 | return min + randomSource.nextInt(maxDelta); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/UnhandledEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | import javax.annotation.Nonnull; 22 | 23 | public class UnhandledEnum extends AssertionError 24 | { 25 | public UnhandledEnum(@Nonnull Enum value) 26 | { 27 | this("Unhandled ", value); 28 | } 29 | 30 | private UnhandledEnum(String prefix, @Nonnull Enum value) 31 | { 32 | super(prefix + value.getClass().getSimpleName() + ": " + value); 33 | } 34 | 35 | public static UnhandledEnum invalid(@Nonnull Enum value) 36 | { 37 | return new UnhandledEnum("Invalid ", value); 38 | } 39 | 40 | public static UnhandledEnum unknown(@Nonnull Enum value) 41 | { 42 | return new UnhandledEnum("Unknown ", value); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/DebugMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | import java.util.List; 22 | 23 | import com.google.common.collect.Lists; 24 | 25 | import accord.coordinate.Timeout; 26 | import accord.local.Node; 27 | 28 | public class DebugMap extends SortedListMap 29 | { 30 | private static final Timeout timeoutInstance = Timeout.unsafeTimeout(null, null); 31 | 32 | public DebugMap(SortedList list) 33 | { 34 | super(list, Object[]::new); 35 | } 36 | 37 | public void debug(Node.Id from, Object reply) 38 | { 39 | if (reply == null) 40 | reply = timeoutInstance; 41 | merge(from, reply, (a, b) -> a instanceof List ? ((List) a).add(b) : Lists.newArrayList(a, b)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/topology/TopologyRetiredException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.topology; 20 | 21 | public class TopologyRetiredException extends TopologyException 22 | { 23 | public TopologyRetiredException(long epoch, long minEpoch) 24 | { 25 | super(message(epoch, minEpoch)); 26 | } 27 | 28 | public TopologyRetiredException(String message, TopologyRetiredException t) 29 | { 30 | super(message, t); 31 | } 32 | 33 | public static String message(long epoch, long minEpoch) 34 | { 35 | return String.format("Topology %d retired. Min topology %d", epoch, minEpoch); 36 | } 37 | 38 | @Override 39 | public TopologyException rethrowable() 40 | { 41 | return new TopologyRetiredException(getMessage(), this); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /accord-maelstrom/src/main/java/accord/maelstrom/MaelstromReplyContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.maelstrom; 20 | 21 | import accord.messages.ReplyContext; 22 | 23 | public class MaelstromReplyContext implements ReplyContext 24 | { 25 | public final long messageId; 26 | 27 | public MaelstromReplyContext(long messageId) 28 | { 29 | this.messageId = messageId; 30 | } 31 | 32 | public static ReplyContext contextFor(long messageId) 33 | { 34 | return new MaelstromReplyContext(messageId); 35 | } 36 | 37 | public static long messageIdFor(ReplyContext replyContext) 38 | { 39 | if (replyContext instanceof Packet) 40 | return ((Packet) replyContext).body.msg_id; 41 | return ((MaelstromReplyContext) replyContext).messageId; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /accord-maelstrom/src/main/java/accord/maelstrom/MaelstromData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.maelstrom; 20 | 21 | import java.util.TreeMap; 22 | 23 | import accord.api.Data; 24 | import accord.api.Key; 25 | import accord.primitives.Ranges; 26 | 27 | public class MaelstromData extends TreeMap implements Data 28 | { 29 | @Override 30 | public Data merge(Data data) 31 | { 32 | if (data != null) 33 | this.putAll(((MaelstromData)data)); 34 | return this; 35 | } 36 | 37 | @Override 38 | public Data without(Ranges ranges) 39 | { 40 | MaelstromData result = new MaelstromData(); 41 | forEach((key, value) -> { 42 | if (!ranges.contains(key)) 43 | result.put(key, value); 44 | }); 45 | return result; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/topology/TopologyNotReadyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.topology; 20 | 21 | public final class TopologyNotReadyException extends TopologyException 22 | { 23 | public TopologyNotReadyException(long epoch, long currentEpoch) 24 | { 25 | super(message(epoch, currentEpoch)); 26 | } 27 | 28 | public TopologyNotReadyException(String message, TopologyNotReadyException t) 29 | { 30 | super(message, t); 31 | } 32 | 33 | public static String message(long epoch, long currentEpoch) 34 | { 35 | return String.format("Topology %d is not ready. Current topology %d", epoch, currentEpoch); 36 | } 37 | 38 | @Override 39 | public TopologyException rethrowable() 40 | { 41 | return new TopologyNotReadyException(getMessage(), this); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/WrapAroundList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | import java.util.AbstractList; 22 | 23 | public class WrapAroundList extends AbstractList 24 | { 25 | final T[] contents; 26 | final int start, end, size; 27 | 28 | public WrapAroundList(T[] contents, int start, int end) 29 | { 30 | this.contents = contents; 31 | this.start = start; 32 | this.end = end; 33 | this.size = end > start ? end - start : end + (contents.length - start); 34 | } 35 | 36 | 37 | @Override 38 | public T get(int index) 39 | { 40 | int i = start + index; 41 | if (i >= contents.length) i -= contents.length; 42 | return contents[i]; 43 | } 44 | 45 | @Override 46 | public int size() 47 | { 48 | return size; 49 | } 50 | } -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/primitives/TimestampWithUniqueHlc.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.primitives; 20 | 21 | import accord.local.Node.Id; 22 | import accord.utils.Invariants; 23 | 24 | public final class TimestampWithUniqueHlc extends Timestamp 25 | { 26 | final long uniqueHlc; 27 | 28 | public TimestampWithUniqueHlc(Timestamp copy, long uniqueHlc) 29 | { 30 | super(copy); 31 | this.uniqueHlc = uniqueHlc; 32 | Invariants.require(uniqueHlc != hlc()); 33 | } 34 | 35 | public TimestampWithUniqueHlc(long epoch, long hlc, long uniqueHlc, int flags, Id node) 36 | { 37 | super(epoch, hlc, flags, node); 38 | this.uniqueHlc = uniqueHlc; 39 | Invariants.require(uniqueHlc != hlc); 40 | } 41 | 42 | public long uniqueHlc() 43 | { 44 | return uniqueHlc; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/messages/Reply.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.messages; 20 | 21 | import javax.annotation.Nonnull; 22 | 23 | import static accord.messages.MessageType.StandardMessage.FAILURE_RSP; 24 | 25 | public interface Reply extends Message 26 | { 27 | default boolean isFinal() { return true; } 28 | 29 | class FailureReply implements Reply 30 | { 31 | @Nonnull 32 | public final Throwable failure; 33 | 34 | public FailureReply(@Nonnull Throwable failure) 35 | { 36 | this.failure = failure; 37 | } 38 | 39 | @Override 40 | public MessageType type() 41 | { 42 | return FAILURE_RSP; 43 | } 44 | 45 | @Override 46 | public String toString() 47 | { 48 | return failure.toString(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/api/UncaughtExceptionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.api; 20 | 21 | import java.util.function.BiConsumer; 22 | import java.util.function.Function; 23 | 24 | import accord.utils.Rethrowable; 25 | 26 | public interface UncaughtExceptionListener extends BiConsumer 27 | { 28 | void onException(Throwable t); 29 | 30 | @Override 31 | default void accept(Object ignore, Throwable t) 32 | { 33 | if (t != null) 34 | onException(t); 35 | } 36 | 37 | default void accept(Object ignore, Throwable t, Function ifException) 38 | { 39 | if (t != null) 40 | onException(ifException.apply(t)); 41 | } 42 | 43 | default void acceptAndWrap(Object ignore, Throwable t) 44 | { 45 | accept(ignore, t, Rethrowable::rethrowable); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /accord-core/src/test/java/accord/burn/SimulationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.burn; 20 | 21 | public class SimulationException extends RuntimeException 22 | { 23 | public SimulationException(long seed, Throwable t) 24 | { 25 | super(createMsg(seed, null), t, true, false); 26 | } 27 | 28 | public SimulationException(long seed, String msg, Throwable t) 29 | { 30 | super(createMsg(seed, msg), t, true, false); 31 | } 32 | 33 | private static String createMsg(long seed, String msg) 34 | { 35 | return String.format("Failed on seed %d%s", seed, msg == null ? "" : "; " + msg); 36 | } 37 | 38 | public static SimulationException wrap(long seed, Throwable t) 39 | { 40 | if (t instanceof SimulationException) 41 | return (SimulationException) t; 42 | return new SimulationException(seed, t); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /accord-core/src/test/java/accord/utils/CRCUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | import java.util.zip.CRC32; 22 | 23 | public class CRCUtils 24 | { 25 | private static final int POLY = 0xedb88320; 26 | 27 | private CRCUtils() {} 28 | 29 | public static int crc32LittleEnding(int key) 30 | { 31 | CRC32 crc32c = new CRC32(); 32 | crc32c.update(key); 33 | crc32c.update(key >> 8); 34 | crc32c.update(key >> 16); 35 | crc32c.update(key >> 24); 36 | return (int) crc32c.getValue(); 37 | } 38 | 39 | public static int reverseCRC32LittleEnding(int c) 40 | { 41 | for (int i = 0; i < 32; i++) 42 | { 43 | c = (c >>> 31) == 0 ? 44 | (c ^ POLY) << 1 | 1 45 | : c << 1; 46 | } 47 | // flip bits 48 | c = c ^ 0xffffffff; 49 | return c; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /accord-maelstrom/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | plugins { 20 | id 'accord.java-conventions' 21 | } 22 | 23 | dependencies { 24 | implementation project(':accord-core') 25 | implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2' 26 | implementation 'com.google.code.gson:gson:2.8.7' 27 | 28 | testImplementation project(':accord-core').sourceSets.test.output 29 | } 30 | 31 | jar { 32 | manifest { 33 | attributes( 34 | 'Main-Class': 'accord.maelstrom.Main', 35 | ) 36 | } 37 | } 38 | 39 | task fatJar(type: Jar) { 40 | manifest.from jar.manifest 41 | archiveClassifier = 'all' 42 | from { 43 | configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } 44 | } { 45 | exclude "META-INF/*.SF" 46 | exclude "META-INF/*.DSA" 47 | exclude "META-INF/*.RSA" 48 | } 49 | with jar 50 | } 51 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/MapReduce.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | import java.util.function.BiFunction; 22 | import java.util.function.Function; 23 | 24 | public interface MapReduce extends Function, Reduce 25 | { 26 | // TODO (desired, safety): ensure mutual exclusivity when calling each of these methods 27 | @Override 28 | O apply(I in); 29 | O reduce(O o1, O o2); 30 | 31 | static MapReduce of(Function map, BiFunction reduce) 32 | { 33 | return new MapReduce() 34 | { 35 | @Override 36 | public O apply(I in) 37 | { 38 | return map.apply(in); 39 | } 40 | 41 | @Override 42 | public O reduce(O o1, O o2) 43 | { 44 | return reduce.apply(o1, o2); 45 | } 46 | }; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/UncheckedInterruptedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | public class UncheckedInterruptedException extends RuntimeException 22 | { 23 | public UncheckedInterruptedException() 24 | { 25 | super(); 26 | } 27 | 28 | public UncheckedInterruptedException(String message) 29 | { 30 | super(message); 31 | } 32 | 33 | public UncheckedInterruptedException(String message, InterruptedException cause) 34 | { 35 | super(message, cause); 36 | } 37 | 38 | public UncheckedInterruptedException(InterruptedException cause) 39 | { 40 | super(cause); 41 | } 42 | 43 | protected UncheckedInterruptedException(String message, InterruptedException cause, boolean enableSuppression, boolean writableStackTrace) 44 | { 45 | super(message, cause, enableSuppression, writableStackTrace); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/api/Update.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.api; 20 | 21 | import javax.annotation.Nullable; 22 | 23 | import accord.primitives.Participants; 24 | import accord.primitives.Ranges; 25 | import accord.primitives.Seekables; 26 | import accord.primitives.Timestamp; 27 | 28 | /** 29 | * A client-defined update operation (the write equivalent of a query). 30 | * Takes as input the data returned by {@code Read}, and returns a {@code Write} 31 | * representing new information to distributed to each shard's stores. 32 | * 33 | * Update will be invoked after Query at a coordinator 34 | */ 35 | public interface Update extends Sliceable 36 | { 37 | Seekables keys(); 38 | // null is provided only if nothing was read 39 | Write apply(Timestamp executeAt, @Nullable Data data); 40 | Update slice(Ranges ranges); 41 | Update intersecting(Participants participants); 42 | Update merge(Update other); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /accord-maelstrom/src/main/java/accord/maelstrom/MaelstromInit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.maelstrom; 20 | 21 | import java.io.IOException; 22 | 23 | import accord.maelstrom.Packet.Type; 24 | import com.google.gson.stream.JsonWriter; 25 | import accord.local.Node.Id; 26 | 27 | public class MaelstromInit extends Body 28 | { 29 | final Id self; 30 | final Id[] cluster; 31 | 32 | public MaelstromInit(long msg_id, Id self, Id[] cluster) 33 | { 34 | super(Type.init, msg_id, SENTINEL_MSG_ID); 35 | this.self = self; 36 | this.cluster = cluster; 37 | } 38 | 39 | @Override 40 | void writeBody(JsonWriter out) throws IOException 41 | { 42 | super.writeBody(out); 43 | out.name("node_id"); 44 | out.value(self.id); 45 | out.name("node_ids"); 46 | out.beginArray(); 47 | for (Id node : cluster) 48 | out.value(node.id); 49 | out.endArray(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /accord-maelstrom/src/main/java/accord/maelstrom/SimpleTopologyService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.maelstrom; 20 | 21 | import accord.api.TopologyService; 22 | import accord.local.Node; 23 | import accord.topology.Topology; 24 | import accord.utils.Invariants; 25 | import accord.utils.async.AsyncResult; 26 | import accord.utils.async.AsyncResults; 27 | 28 | public class SimpleTopologyService implements TopologyService 29 | { 30 | private final Topology topology; 31 | 32 | public SimpleTopologyService(Topology topology) 33 | { 34 | this.topology = topology; 35 | } 36 | 37 | @Override 38 | public AsyncResult fetchTopologyForEpoch(long epoch) 39 | { 40 | Invariants.require(epoch == topology.epoch()); 41 | return AsyncResults.success(topology); 42 | } 43 | 44 | @Override 45 | public void onStartup(Node node) 46 | { 47 | node.topology().reportTopology(topology); 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/impl/AbstractAsyncExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.impl; 20 | 21 | import java.util.concurrent.Callable; 22 | 23 | import accord.api.AsyncExecutor; 24 | import accord.utils.async.AsyncChain; 25 | import accord.utils.async.AsyncChains; 26 | 27 | // we keep this as a separate interface for simulator compatibility, 28 | // else we use the wrong class loader's AsyncChain.Head. 29 | public interface AbstractAsyncExecutor extends AsyncExecutor 30 | { 31 | @Override 32 | default AsyncChain chain(Runnable run) 33 | { 34 | return AsyncChains.chain(this, run); 35 | } 36 | 37 | @Override 38 | default AsyncChain chain(Callable call) 39 | { 40 | return AsyncChains.chain(this, call); 41 | } 42 | 43 | @Override 44 | default AsyncChain flatChain(Callable> call) 45 | { 46 | return AsyncChains.flatChain(this, call); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/coordinate/EpochTimeout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.coordinate; 20 | 21 | import accord.api.Agent; 22 | import accord.utils.Invariants; 23 | 24 | public class EpochTimeout extends Timeout 25 | { 26 | public final long epoch; 27 | 28 | public static EpochTimeout timeout(long epoch, Agent agent) 29 | { 30 | agent.coordinatorEvents().onEpochTimeout(epoch); 31 | return new EpochTimeout(epoch); 32 | } 33 | 34 | EpochTimeout(long epoch) 35 | { 36 | super(null, null, "Timeout waiting for epoch " + epoch); 37 | this.epoch = epoch; 38 | } 39 | 40 | private EpochTimeout(long epoch, EpochTimeout cause) 41 | { 42 | super(null, null, cause); 43 | this.epoch = epoch; 44 | } 45 | 46 | @Override 47 | public EpochTimeout rethrowable() 48 | { 49 | Invariants.require(this.getClass() == EpochTimeout.class); 50 | return new EpochTimeout(epoch, this); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/random/Suppliers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils.random; 20 | 21 | import java.util.function.BooleanSupplier; 22 | import java.util.function.IntSupplier; 23 | import java.util.function.LongSupplier; 24 | import java.util.function.Supplier; 25 | 26 | public class Suppliers 27 | { 28 | public interface Bools extends BooleanSupplier 29 | { 30 | boolean get(); 31 | void cycle(); 32 | default boolean getAsBoolean() { return get(); } 33 | } 34 | 35 | public interface Ints extends IntSupplier 36 | { 37 | int get(); 38 | void cycle(); 39 | default int getAsInt() { return get(); } 40 | } 41 | 42 | public interface Longs extends LongSupplier 43 | { 44 | long get(); 45 | void cycle(); 46 | default long getAsLong() { return get(); } 47 | } 48 | 49 | public interface Objects extends Supplier 50 | { 51 | T get(); 52 | void cycle(); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /accord-core/src/test/java/accord/coordinate/FailureAccumulatorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.coordinate; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import static org.assertj.core.api.Assertions.assertThat; 24 | 25 | class FailureAccumulatorTest 26 | { 27 | @Test 28 | public void firstTimeout() 29 | { 30 | testNonTimeout(true); 31 | } 32 | 33 | @Test 34 | public void firstNotTimeout() 35 | { 36 | testNonTimeout(false); 37 | } 38 | 39 | private static void testNonTimeout(boolean firstTimeout) 40 | { 41 | Throwable accum = firstTimeout ? null : new IllegalStateException(); 42 | accum = FailureAccumulator.append(accum, new IllegalStateException()); 43 | accum = FailureAccumulator.append(accum, null); 44 | 45 | assertThat(accum).isInstanceOf(IllegalStateException.class); 46 | Throwable[] sup = accum.getSuppressed(); 47 | if (!firstTimeout) assertThat(sup[0]).isInstanceOf(IllegalStateException.class); 48 | } 49 | } -------------------------------------------------------------------------------- /accord-maelstrom/src/main/java/accord/maelstrom/Error.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.maelstrom; 20 | 21 | import java.io.IOException; 22 | 23 | import accord.maelstrom.Packet.Type; 24 | import accord.messages.MessageType; 25 | import accord.messages.Reply; 26 | import com.google.gson.stream.JsonWriter; 27 | 28 | public class Error extends Body implements Reply 29 | { 30 | final int code; 31 | final String text; 32 | 33 | public Error(long in_reply_to, int code, String text) 34 | { 35 | super(Type.error, SENTINEL_MSG_ID, in_reply_to); 36 | this.code = code; 37 | this.text = text; 38 | } 39 | 40 | @Override 41 | void writeBody(JsonWriter out) throws IOException 42 | { 43 | super.writeBody(out); 44 | out.name("code"); 45 | out.value(code); 46 | out.name("text"); 47 | out.value(text); 48 | } 49 | 50 | @Override 51 | public MessageType type() 52 | { 53 | throw new UnsupportedOperationException(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /accord-core/src/test/java/accord/impl/basic/PendingQueue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.impl.basic; 20 | 21 | import java.util.List; 22 | import java.util.concurrent.TimeUnit; 23 | import java.util.function.Predicate; 24 | 25 | public interface PendingQueue extends Iterable 26 | { 27 | void add(Pending item); 28 | void addNoDelay(Pending item); 29 | void add(Pending item, long delay, TimeUnit units); 30 | 31 | /** 32 | * Register an item we intend to add later. 33 | * This is primarily for tracking the number of recurring tasks there are pending to run, 34 | * including those that are being tracked pre-submission as e.g. tasks in a logical executor that cannot be 35 | * scheduled until the preceding tasks have completed. 36 | */ 37 | void preregister(Pending item); 38 | 39 | boolean remove(Pending item); 40 | Pending poll(); 41 | List drain(Predicate toDrain); 42 | int size(); 43 | long nowInMillis(); 44 | 45 | boolean hasNonRecurring(); 46 | } 47 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/utils/WrapAroundSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | import java.util.AbstractSet; 22 | import java.util.Iterator; 23 | import java.util.Map; 24 | 25 | public class WrapAroundSet extends AbstractSet 26 | { 27 | final Map lookup; 28 | final WrapAroundList list; 29 | 30 | public WrapAroundSet(Map lookup, WrapAroundList list) 31 | { 32 | this.lookup = lookup; 33 | this.list = list; 34 | } 35 | 36 | @Override 37 | public boolean contains(Object o) 38 | { 39 | Integer i = lookup.get(o); 40 | if (i == null) return false; 41 | if (list.end > list.start) 42 | return i >= list.start && i < list.end; 43 | else 44 | return i >= list.start || i < list.end; 45 | } 46 | 47 | @Override 48 | public Iterator iterator() 49 | { 50 | return list.iterator(); 51 | } 52 | 53 | @Override 54 | public int size() 55 | { 56 | return list.size; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /accord-maelstrom/src/main/java/accord/maelstrom/MaelstromWrite.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.maelstrom; 20 | 21 | import accord.api.Key; 22 | import accord.api.Write; 23 | import accord.local.SafeCommandStore; 24 | import accord.primitives.PartialTxn; 25 | import accord.primitives.Seekable; 26 | import accord.primitives.Timestamp; 27 | import accord.primitives.TxnId; 28 | import accord.utils.Timestamped; 29 | import accord.utils.async.AsyncChain; 30 | import accord.utils.async.AsyncChains; 31 | 32 | import java.util.TreeMap; 33 | 34 | public class MaelstromWrite extends TreeMap implements Write 35 | { 36 | @Override 37 | public AsyncChain apply(SafeCommandStore safeStore, Seekable key, TxnId txnId, Timestamp executeAt, PartialTxn txn) 38 | { 39 | MaelstromStore dataStore = (MaelstromStore) safeStore.dataStore(); 40 | if (containsKey(key)) 41 | dataStore.data.merge((Key)key, new Timestamped<>(executeAt, get(key), Value::toString), Timestamped::merge); 42 | return AsyncChains.success(null); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/api/Query.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.api; 20 | 21 | import javax.annotation.Nonnull; 22 | import javax.annotation.Nullable; 23 | 24 | import accord.primitives.Seekables; 25 | import accord.primitives.Timestamp; 26 | import accord.primitives.TxnId; 27 | 28 | /** 29 | * The computational/transformation part of a client query 30 | * 31 | * Query will be invoked at a coordinator before Update 32 | */ 33 | public interface /**/Query 34 | { 35 | /** 36 | * Perform some transformation on the complete {@link Data} result of a {@link Read} 37 | * from some {@link DataStore}, to produce a {@link Result} to return to the client. 38 | * 39 | * executeAt timestamp is provided so that the result of the transaction can be determined based 40 | * on configuration at that epoch. This will be deterministic even if the transaction is recovered. 41 | */ 42 | Result compute(@Nonnull TxnId txnId, @Nonnull Timestamp executeAt, @Nonnull Seekables keys, @Nullable Data data, @Nullable Read read, @Nullable Update update); 43 | } 44 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/coordinate/Truncated.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.coordinate; 20 | 21 | import javax.annotation.Nullable; 22 | 23 | import accord.api.RoutingKey; 24 | import accord.primitives.TxnId; 25 | import accord.utils.Invariants; 26 | 27 | /** 28 | * Thrown when a transaction's state has been truncated prior to the completion of some operation upon it 29 | */ 30 | public class Truncated extends CoordinationFailed 31 | { 32 | public Truncated(TxnId txnId, @Nullable RoutingKey homeKey) 33 | { 34 | super(txnId, homeKey); 35 | } 36 | 37 | public Truncated(TxnId txnId, @Nullable RoutingKey homeKey, String message) 38 | { 39 | super(txnId, homeKey, message); 40 | } 41 | 42 | private Truncated(TxnId txnId, @Nullable RoutingKey homeKey, Truncated cause) 43 | { 44 | super(txnId, homeKey, cause); 45 | } 46 | 47 | @Override 48 | public Truncated rethrowable() 49 | { 50 | Invariants.require(this.getClass() == Truncated.class); 51 | return new Truncated(txnId(), homeKey(), this); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/impl/InMemorySafeCommandsForKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.impl; 20 | 21 | import accord.api.RoutingKey; 22 | import accord.impl.InMemoryCommandStore.GlobalCommandsForKey; 23 | import accord.local.cfk.CommandsForKey; 24 | import accord.local.cfk.SafeCommandsForKey; 25 | 26 | public class InMemorySafeCommandsForKey extends SafeCommandsForKey 27 | { 28 | private boolean invalidated = false; 29 | private final GlobalCommandsForKey global; 30 | 31 | public InMemorySafeCommandsForKey(RoutingKey key, GlobalCommandsForKey global) 32 | { 33 | super(key); 34 | this.global = global; 35 | } 36 | 37 | @Override 38 | public CommandsForKey current() 39 | { 40 | return global.value(); 41 | } 42 | 43 | @Override 44 | protected void set(CommandsForKey update) 45 | { 46 | global.value(update); 47 | } 48 | 49 | public void invalidate() 50 | { 51 | invalidated = true; 52 | } 53 | 54 | public boolean invalidated() 55 | { 56 | return invalidated; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /accord-core/src/test/java/accord/utils/UtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.utils; 20 | 21 | import java.util.List; 22 | import java.util.stream.IntStream; 23 | 24 | import com.google.common.primitives.Ints; 25 | import org.junit.jupiter.api.Test; 26 | 27 | import static accord.utils.Property.qt; 28 | import static accord.utils.Utils.reduce; 29 | import static org.assertj.core.api.Assertions.assertThat; 30 | 31 | class UtilsTest 32 | { 33 | @Test 34 | public void simpleReduce() 35 | { 36 | qt().forAll(Gens.arrays(Gens.ints().all()).ofSizeBetween(0, 10)).check(array -> { 37 | List list = Ints.asList(array); 38 | 39 | // filter doesn't return non matches 40 | assertThat(reduce(true, list, v -> v % 2 == 0, (acc, v) -> acc & (v % 2 == 0))).isTrue(); 41 | // count 42 | assertThat(reduce(0, list, i -> true, (acc, v) -> acc + 1)).isEqualTo(array.length); 43 | // sum 44 | assertThat(reduce(0, list, i -> true, (acc, v) -> acc + v)).isEqualTo(IntStream.of(array).sum()); 45 | }); 46 | } 47 | } -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/api/OwnershipEventListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.api; 20 | 21 | import accord.local.CommandStore; 22 | import accord.primitives.Ranges; 23 | import accord.primitives.Timestamp; 24 | 25 | import static accord.utils.Invariants.illegalState; 26 | 27 | public interface OwnershipEventListener 28 | { 29 | default void onSuccessfulBootstrap(CommandStore commandStore, int attempt, long epoch, Ranges ranges) {} 30 | void onFailedBootstrap(int attempt, String phase, Ranges ranges, Runnable retry, Runnable fail, Throwable failure); 31 | void onStale(Timestamp staleSince, Ranges ranges); 32 | 33 | OwnershipEventListener FAIL = new OwnershipEventListener() 34 | { 35 | @Override public void onSuccessfulBootstrap(CommandStore commandStore, int attempt, long epoch, Ranges ranges) { throw illegalState(); } 36 | @Override public void onFailedBootstrap(int attempt, String phase, Ranges ranges, Runnable retry, Runnable fail, Throwable failure) { throw illegalState(); } 37 | @Override public void onStale(Timestamp staleSince, Ranges ranges) { throw illegalState(); } 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/coordinate/tracking/PreAcceptTracker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.coordinate.tracking; 20 | 21 | import java.util.function.Function; 22 | import java.util.function.IntFunction; 23 | 24 | import accord.local.Node; 25 | import accord.topology.Shard; 26 | import accord.topology.Topologies; 27 | 28 | public abstract class PreAcceptTracker extends AbstractTracker 29 | { 30 | public PreAcceptTracker(Topologies topologies, IntFunction arrayFactory, Function trackerFactory) 31 | { 32 | super(topologies, arrayFactory, trackerFactory); 33 | } 34 | 35 | public

PreAcceptTracker(Topologies topologies, IntFunction arrayFactory, P param, ShardFactory trackerFactory) 36 | { 37 | super(topologies, arrayFactory, param, trackerFactory); 38 | } 39 | 40 | public abstract RequestStatus recordSuccess(Node.Id from, boolean withFastPathTimestamp); 41 | public abstract RequestStatus recordDelayed(Node.Id from); 42 | public abstract boolean hasFastPathAccepted(); 43 | public abstract boolean hasMediumPathAccepted(); 44 | } 45 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/api/BarrierType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.api; 20 | 21 | public enum BarrierType 22 | { 23 | // Only wait until the barrier is achieved locally, and possibly don't trigger the barrier remotely. 24 | // Local barriers are only on the `minEpoch` provided and have utility limited to establishing 25 | // no more transactions will occur in an epoch before minEpoch 26 | // Only keys (not ranges) are supported 27 | local(false, false), 28 | // Wait until the barrier has been achieved at a quorum globally and is also locally applied (global happens before semantics) 29 | global_sync(true, true), 30 | // Trigger the global barrier, but only block on creation of the barrier and local application (local happens before semantics) 31 | global_async(true, false); 32 | 33 | public final boolean global; 34 | 35 | // Whether to wait for persist to achieve quorum synchronously 36 | public final boolean waitOnGlobalQuorum; 37 | 38 | BarrierType(boolean global, boolean waitOnGlobalQuorum) 39 | { 40 | this.global = global; 41 | this.waitOnGlobalQuorum = waitOnGlobalQuorum; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/coordinate/Invalidated.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.coordinate; 20 | 21 | import javax.annotation.Nullable; 22 | 23 | import accord.api.Agent; 24 | import accord.api.RoutingKey; 25 | import accord.primitives.TxnId; 26 | import accord.utils.Invariants; 27 | 28 | /** 29 | * Thrown when a transaction has been invalidated 30 | */ 31 | public class Invalidated extends CoordinationFailed 32 | { 33 | public static Invalidated invalidated(Agent agent, TxnId txnId, @Nullable RoutingKey homeKey) 34 | { 35 | agent.coordinatorEvents().onInvalidated(txnId); 36 | return new Invalidated(txnId, homeKey); 37 | } 38 | 39 | private Invalidated(TxnId txnId, @Nullable RoutingKey homeKey) 40 | { 41 | super(txnId, homeKey); 42 | } 43 | 44 | private Invalidated(TxnId txnId, @Nullable RoutingKey homeKey, Invalidated cause) 45 | { 46 | super(txnId, homeKey, cause); 47 | } 48 | 49 | @Override 50 | public Invalidated rethrowable() 51 | { 52 | Invariants.require(this.getClass() == Invalidated.class); 53 | return new Invalidated(txnId(), homeKey(), this); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /accord-core/src/test/java/accord/impl/TopologyFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.impl; 20 | 21 | 22 | import accord.local.Node; 23 | import accord.primitives.Range; 24 | import accord.primitives.Ranges; 25 | import accord.topology.Topology; 26 | import accord.topology.TopologyUtils; 27 | 28 | import java.util.*; 29 | 30 | import static accord.utils.Utils.toArray; 31 | 32 | public class TopologyFactory 33 | { 34 | public final int rf; 35 | public final Range[] shardRanges; 36 | 37 | public TopologyFactory(int rf, Range... shardRanges) 38 | { 39 | this.rf = rf; 40 | this.shardRanges = shardRanges; 41 | } 42 | 43 | public Topology toTopology(Node.Id[] cluster) 44 | { 45 | return TopologyUtils.initialTopology(cluster, Ranges.ofSortedAndDeoverlapped(shardRanges), rf); 46 | } 47 | 48 | public Topology toTopology(List cluster) 49 | { 50 | return toTopology(toArray(cluster, Node.Id[]::new)); 51 | } 52 | 53 | public static Topology toTopology(List cluster, int rf, Range... ranges) 54 | { 55 | return new TopologyFactory(rf, ranges).toTopology(cluster); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/primitives/RoutableKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.primitives; 20 | 21 | import accord.api.RoutingKey; 22 | import accord.utils.Invariants; 23 | 24 | import javax.annotation.Nonnull; 25 | import javax.annotation.Nullable; 26 | 27 | public interface RoutableKey extends Routable, Comparable 28 | { 29 | @Override 30 | int compareTo(@Nonnull RoutableKey that); 31 | 32 | @Override 33 | default Domain domain() { return Domain.Key; } 34 | 35 | @Override 36 | RoutingKey toUnseekable(); 37 | 38 | default int compareAsRoutingKey(@Nonnull RoutableKey that) { return toUnseekable().compareTo(that.toUnseekable()); } 39 | 40 | /** 41 | * Some suffix that, combined with prefix(), uniquely identifies the Key. 42 | * 43 | * TODO (expected): distinguish this from printableSuffix 44 | */ 45 | Object suffix(); 46 | 47 | default Object printableSuffix() { return suffix(); } 48 | 49 | @Override default RoutingKey someIntersectingRoutingKey(@Nullable Ranges ranges) 50 | { 51 | Invariants.paranoid(ranges == null || ranges.contains(this)); 52 | return toUnseekable(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/coordinate/PersistSyncPoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.coordinate; 20 | 21 | import accord.api.Result; 22 | import accord.coordinate.ExecuteFlag.CoordinationFlags; 23 | import accord.local.Node; 24 | import accord.local.SequentialAsyncExecutor; 25 | import accord.messages.Apply; 26 | import accord.primitives.Ballot; 27 | import accord.primitives.Deps; 28 | import accord.primitives.FullRoute; 29 | import accord.primitives.Route; 30 | import accord.primitives.Timestamp; 31 | import accord.primitives.Txn; 32 | import accord.primitives.TxnId; 33 | import accord.primitives.Writes; 34 | import accord.topology.Topologies; 35 | 36 | public class PersistSyncPoint extends Persist 37 | { 38 | public PersistSyncPoint(Node node, SequentialAsyncExecutor executor, Topologies topologies, TxnId txnId, Ballot ballot, Route sendTo, Txn txn, Timestamp executeAt, Deps deps, Writes writes, Result result, boolean informDurableOnDone, FullRoute route, Apply.Kind applyKind) 39 | { 40 | super(node, executor, topologies, txnId, ballot, sendTo, txn, executeAt, deps, writes, result, route, CoordinationFlags.none(), informDurableOnDone, Apply.FACTORY, applyKind); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/coordinate/StabiliseSyncPoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.coordinate; 20 | 21 | import java.util.function.BiConsumer; 22 | 23 | import accord.local.Node; 24 | import accord.local.SequentialAsyncExecutor; 25 | import accord.primitives.Ballot; 26 | import accord.primitives.Deps; 27 | import accord.primitives.FullRoute; 28 | import accord.primitives.Timestamp; 29 | import accord.primitives.Txn; 30 | import accord.primitives.TxnId; 31 | import accord.topology.Topologies; 32 | 33 | public class StabiliseSyncPoint extends Stabilise 34 | { 35 | final CoordinationAdapter adapter; 36 | StabiliseSyncPoint(CoordinationAdapter adapter, Node node, SequentialAsyncExecutor executor, Topologies coordinates, Topologies all, FullRoute route, Ballot ballot, TxnId txnId, Txn txn, Timestamp executeAt, Deps unstableDeps, BiConsumer callback) 37 | { 38 | super(node, executor, coordinates, all, route, route, txnId, ballot, txn, executeAt, unstableDeps, callback); 39 | this.adapter = adapter; 40 | } 41 | 42 | @Override 43 | protected CoordinationAdapter adapter() 44 | { 45 | return adapter; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/coordinate/Preempted.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.coordinate; 20 | 21 | import javax.annotation.Nullable; 22 | 23 | import accord.api.Agent; 24 | import accord.api.RoutingKey; 25 | import accord.primitives.TxnId; 26 | import accord.utils.Invariants; 27 | 28 | /** 29 | * Thrown when a coordinator is preempted by another recovery 30 | * coordinator intending to complete the transaction 31 | */ 32 | public class Preempted extends CoordinationFailed 33 | { 34 | public static Preempted preempted(Agent agent, TxnId txnId, @Nullable RoutingKey homeKey) 35 | { 36 | agent.coordinatorEvents().onPreempted(txnId); 37 | return new Preempted(txnId, homeKey); 38 | } 39 | 40 | private Preempted(TxnId txnId, @Nullable RoutingKey homeKey) 41 | { 42 | super(txnId, homeKey); 43 | } 44 | 45 | private Preempted(TxnId txnId, @Nullable RoutingKey homeKey, Preempted cause) 46 | { 47 | super(txnId, homeKey, cause); 48 | } 49 | 50 | @Override 51 | public Preempted rethrowable() 52 | { 53 | Invariants.require(this.getClass() == Preempted.class); 54 | return new Preempted(txnId(), homeKey(), this); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/coordinate/Redundant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.coordinate; 20 | 21 | import javax.annotation.Nullable; 22 | 23 | import accord.api.RoutingKey; 24 | import accord.primitives.Timestamp; 25 | import accord.primitives.TxnId; 26 | import accord.utils.Invariants; 27 | 28 | /** 29 | * Thrown when a coordinator encounters a phase that is ahead of the one it is attempting to progress. 30 | */ 31 | public class Redundant extends CoordinationFailed 32 | { 33 | public final Timestamp committedExecuteAt; 34 | public Redundant(TxnId txnId, @Nullable RoutingKey homeKey, Timestamp committedExecuteAt) 35 | { 36 | super(txnId, homeKey); 37 | this.committedExecuteAt = committedExecuteAt; 38 | } 39 | 40 | Redundant(TxnId txnId, @Nullable RoutingKey homeKey, Redundant cause, Timestamp committedExecuteAt) 41 | { 42 | super(txnId, homeKey, cause); 43 | this.committedExecuteAt = committedExecuteAt; 44 | } 45 | 46 | @Override 47 | public Redundant rethrowable() 48 | { 49 | Invariants.require(this.getClass() == Redundant.class); 50 | return new Redundant(txnId(), homeKey(), this, committedExecuteAt); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /accord-core/src/main/java/accord/coordinate/ProposeTxn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package accord.coordinate; 20 | 21 | import java.util.function.BiConsumer; 22 | 23 | import accord.api.Result; 24 | import accord.local.Node; 25 | import accord.local.SequentialAsyncExecutor; 26 | import accord.messages.Accept; 27 | import accord.primitives.Ballot; 28 | import accord.primitives.Deps; 29 | import accord.primitives.FullRoute; 30 | import accord.primitives.Timestamp; 31 | import accord.primitives.Txn; 32 | import accord.primitives.TxnId; 33 | import accord.topology.Topologies; 34 | 35 | import static accord.coordinate.CoordinationAdapter.Factory.Kind.Standard; 36 | 37 | class ProposeTxn extends Propose 38 | { 39 | ProposeTxn(Node node, SequentialAsyncExecutor executor, Topologies topologies, FullRoute route, Accept.Kind kind, Ballot ballot, TxnId txnId, Txn txn, Timestamp executeAt, Deps deps, BiConsumer callback) 40 | { 41 | super(node, executor, topologies, kind, ballot, txnId, txn, route, route, executeAt, deps, callback); 42 | } 43 | 44 | protected CoordinationAdapter adapter() 45 | { 46 | return node.coordinationAdapter(txnId, Standard); 47 | } 48 | } 49 | --------------------------------------------------------------------------------