belliottsmith commented on code in PR #113: URL: https://github.com/apache/cassandra-accord/pull/113#discussion_r1746018169
########## accord-core/src/main/java/accord/impl/progresslog/BaseTxnState.java: ########## @@ -0,0 +1,211 @@ +/* + * 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.progresslog; + +import javax.annotation.Nullable; + +import accord.api.ProgressLog.BlockedUntil; +import accord.local.SafeCommandStore; +import accord.primitives.TxnId; +import accord.utils.Invariants; +import accord.utils.LogGroupTimers; + +import static accord.impl.progresslog.TxnStateKind.Home; +import static accord.impl.progresslog.TxnStateKind.Waiting; + +/** + * We have a slightly odd class hierarchy here to cleanly group the logic, though TxnState can logically + * be read as a single class. + * <p> + * We have: + * - BaseTxnState defines the state that each of the child classes operate on and provides shared + * methods for updating it, particularly with relation to tracking timer scheduling + * - WaitingState defines the methods for updating the WaitingState state machine (i.e. for local commands that are waiting on a dependency's outcome) + * - HomeState defines the methods for updating the HomeState state machine (i.e. for coordinators ensuring a transaction completes) + * <p> + * TODO (required): unit test all bit fiddling methods + */ +abstract class BaseTxnState extends LogGroupTimers.Timer implements Comparable<BaseTxnState> +{ + private static final int PENDING_TIMER_LOW_SHIFT = 48; + private static final int PENDING_TIMER_LOW_BITS = 4; // can safely free up at least 6 bits here if we need some later + private static final long PENDING_TIMER_LOW_MASK = (1 << PENDING_TIMER_LOW_BITS) - 1; + private static final int PENDING_TIMER_HIGH_SHIFT = 52; + private static final long PENDING_TIMER_HIGH_MASK = (1 << 5) - 1; + private static final long PENDING_TIMER_CLEAR_MASK = ~((PENDING_TIMER_HIGH_MASK << PENDING_TIMER_HIGH_SHIFT) + | (PENDING_TIMER_LOW_MASK << PENDING_TIMER_LOW_SHIFT)); + private static final int SCHEDULED_TIMER_SHIFT = 58; + private static final int RETRY_COUNTER_SHIFT = 59; + private static final long RETRY_COUNTER_MASK = 0xf; + private static final int CONTACT_ALL_SHIFT = 63; + + public final TxnId txnId; + + /** + * bits [0..22) encode BlockingState + * 2 bits for BlockedUntil target + * 2 bits for BlockedUntil that home shard can satisfy + * 2 bits for Progress + * 16 bits for remote progress key counter [note: if we need to in future we can safely and easily reclaim bits here] + * <p> + * bits [22..48) encode HomeState + * 2 bits for CoordinatePhase + * 2 bits for CoordinatorActivity + * 2 bits for Progress + * 20 bits for remote progress key bitset/counter [note: if we need to in future we can safely and easily reclaim bits here] + * <p> + * bits [48..57) for pending timer delay + * bit 57 for queued timer + * bits [58..62) for fallback queue delay back-off counter + * bit 62 for whether the scheduled timer is a fallback timeout (primarily to validate our remote callbacks are still registered) + * bit 63 for whether we should contact all candidate replicas (rather than just our preferred group) + */ + long encodedState; Review Comment: Why would online upgrade be a problem? this is all in-memory. To answer your question: this information is all needed to ensure progress of the transaction execution state machines, and might live for a long time and may cover many transactions. My primary goal was getting this as memory-efficient as possible. Secondarily, we may later also support evicting from memory, though I hope this work precludes that being necessary, -- 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]

