belliottsmith commented on code in PR #113: URL: https://github.com/apache/cassandra-accord/pull/113#discussion_r1746005799
########## accord-core/src/main/java/accord/impl/DefaultRemoteListeners.java: ########## @@ -0,0 +1,525 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package accord.impl; + +import java.util.Arrays; +import java.util.concurrent.ConcurrentHashMap; + +import com.google.common.annotations.VisibleForTesting; + +import accord.api.RemoteListeners; +import accord.local.Command; +import accord.local.Node; +import accord.local.SafeCommand; +import accord.local.SafeCommandStore; +import accord.local.SaveStatus; +import accord.local.Status.Durability; +import accord.messages.Await.AsyncAwaitComplete; +import accord.primitives.Route; +import accord.primitives.TxnId; +import accord.utils.Invariants; +import accord.utils.SortedArrays; +import accord.utils.btree.BTree; + +// TODO (required): evict to disk +public class DefaultRemoteListeners implements RemoteListeners +{ + public interface NotifySink + { + void notify(TxnId txnId, SaveStatus saveStatus, Route<?> participants, long[] listeners, int listenerCount); + } + + public static class DefaultNotifySink implements NotifySink + { + final Node node; + public DefaultNotifySink(Node node) + { + this.node = node; + } + + @Override + public void notify(TxnId txnId, SaveStatus saveStatus, Route<?> route, long[] listeners, int listenerCount) + { + for (int i = 0 ; i < listenerCount ; ++i) + { + long listener = listeners[i]; + // we could in theory reply to the same node multiple times here, but should not be common enough to optimise + Node.Id replyTo = new Node.Id(listenerNodeId(listener)); + int callbackId = listenerCallbackId(listener); + node.send(replyTo, new AsyncAwaitComplete(txnId, route, saveStatus, callbackId)); + } + } + } + + static class StatusListeners + { + final int await; + + // waitingOn is sorted, but to save time on deletions we only set the top bit to mark deleted + // until we have halved the number of entries, at which point we remove the tombstones + // waitingOnSize tracks the top entry, waitingOnCount the number of live entries + int[] waitingOn; + long[] listeners; + int waitingOnSize, waitingOnCount, listenerCount; + + StatusListeners(SaveStatus awaitSaveStatus, Durability awaitDurability, int[] waitingOn, int waitingOnCount, int listenerNodeId, int listenerCallbackId) Review Comment: That's the idea, yes - what this means is we might delay a reply that was waiting on just a subset of stores. But this is probably not all that common. I don't mind if we do want to try and manage these separately, though. We could pack the information efficiently if we wanted to, for instance by encoding bit sets for each listener into some number of longs. This does have the advantage of not creating false dependencies for progress, but I don't _think_ that should ever cause any actual practical problems. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

