From 10af6fec6b489200615909bb7e9888f0a18c8409 Mon Sep 17 00:00:00 2001 From: oliviarla Date: Fri, 20 Dec 2024 12:29:13 +0900 Subject: [PATCH] INTERNAL: rename switchover method and state --- src/main/java/net/spy/memcached/MemcachedConnection.java | 4 ++-- src/main/java/net/spy/memcached/ops/OperationState.java | 5 +++-- .../java/net/spy/memcached/protocol/BaseOperationImpl.java | 4 ++-- .../protocol/ascii/BTreeInsertAndGetOperationImpl.java | 2 +- .../spy/memcached/protocol/ascii/BaseStoreOperationImpl.java | 2 +- .../net/spy/memcached/protocol/ascii/CASOperationImpl.java | 2 +- .../protocol/ascii/CollectionBulkInsertOperationImpl.java | 2 +- .../protocol/ascii/CollectionCreateOperationImpl.java | 2 +- .../protocol/ascii/CollectionDeleteOperationImpl.java | 2 +- .../memcached/protocol/ascii/CollectionGetOperationImpl.java | 2 +- .../protocol/ascii/CollectionInsertOperationImpl.java | 2 +- .../protocol/ascii/CollectionMutateOperationImpl.java | 2 +- .../protocol/ascii/CollectionPipedInsertOperationImpl.java | 2 +- .../protocol/ascii/CollectionPipedUpdateOperationImpl.java | 2 +- .../protocol/ascii/CollectionUpdateOperationImpl.java | 2 +- .../spy/memcached/protocol/ascii/DeleteOperationImpl.java | 2 +- .../memcached/protocol/ascii/FlushByPrefixOperationImpl.java | 2 +- .../net/spy/memcached/protocol/ascii/FlushOperationImpl.java | 2 +- .../spy/memcached/protocol/ascii/MutatorOperationImpl.java | 2 +- .../java/net/spy/memcached/protocol/ascii/OperationImpl.java | 2 +- .../spy/memcached/protocol/ascii/SetAttrOperationImpl.java | 2 +- 21 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/main/java/net/spy/memcached/MemcachedConnection.java b/src/main/java/net/spy/memcached/MemcachedConnection.java index ed9f24a93..04227d542 100644 --- a/src/main/java/net/spy/memcached/MemcachedConnection.java +++ b/src/main/java/net/spy/memcached/MemcachedConnection.java @@ -1000,7 +1000,7 @@ private void handleReads(MemcachedNode qa) assert op == currentOp : "Expected to pop " + currentOp + " got " + op; currentOp = qa.getCurrentReadOp(); /* ENABLE_REPLICATION if */ - } else if (currentOp.getState() == OperationState.MOVING) { + } else if (currentOp.getState() == OperationState.NEED_SWITCHOVER) { break; /* ENABLE_REPLICATION end */ /* ENABLE_MIGRATION if */ @@ -1016,7 +1016,7 @@ private void handleReads(MemcachedNode qa) /* ENABLE_MIGRATION end */ } /* ENABLE_REPLICATION if */ - if (currentOp != null && currentOp.getState() == OperationState.MOVING) { + if (currentOp != null && currentOp.getState() == OperationState.NEED_SWITCHOVER) { ((Buffer) rbuf).clear(); MemcachedReplicaGroup group = qa.getReplicaGroup(); delayedSwitchoverGroups.remove(group); diff --git a/src/main/java/net/spy/memcached/ops/OperationState.java b/src/main/java/net/spy/memcached/ops/OperationState.java index 15205e266..c6de72994 100644 --- a/src/main/java/net/spy/memcached/ops/OperationState.java +++ b/src/main/java/net/spy/memcached/ops/OperationState.java @@ -38,9 +38,10 @@ public enum OperationState { COMPLETE, /* ENABLE_REPLICATION if */ /** - * State indicating this operation will be moved by switchover or failover + * State indicating this operation received SWITCHOVER | REPL_SLAVE + * and the node handling this operation need to switchover in the locator. */ - MOVING, + NEED_SWITCHOVER, /* ENABLE_REPLICATION end */ /* ENABLE_MIGRATION if */ diff --git a/src/main/java/net/spy/memcached/protocol/BaseOperationImpl.java b/src/main/java/net/spy/memcached/protocol/BaseOperationImpl.java index 08362d509..52da18328 100644 --- a/src/main/java/net/spy/memcached/protocol/BaseOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/BaseOperationImpl.java @@ -144,7 +144,7 @@ public final void reset() { } } - protected final void receivedMoveOperations(String cause) { + protected final void prepareSwitchover(String cause) { // switchover message e.g. // one slave node case : "SWITCHOVER", "REPL_SLAVE", // two or more than slave nodes case : "SWITCHOVER ", "REPL_SLAVE " @@ -165,7 +165,7 @@ protected final void receivedMoveOperations(String cause) { } getLogger().info("%s message received by %s operation from %s", cause, this, handlingNode); - transitionState(OperationState.MOVING); + transitionState(OperationState.NEED_SWITCHOVER); } /* ENABLE_REPLICATION end */ diff --git a/src/main/java/net/spy/memcached/protocol/ascii/BTreeInsertAndGetOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/BTreeInsertAndGetOperationImpl.java index bf75631ca..ad4a51d5d 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/BTreeInsertAndGetOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/BTreeInsertAndGetOperationImpl.java @@ -121,7 +121,7 @@ public void handleLine(String line) { /* ENABLE_REPLICATION if */ if (hasSwitchedOver(line)) { - receivedMoveOperations(line); + prepareSwitchover(line); return; } /* ENABLE_REPLICATION end */ diff --git a/src/main/java/net/spy/memcached/protocol/ascii/BaseStoreOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/BaseStoreOperationImpl.java index bc8508379..441d4517d 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/BaseStoreOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/BaseStoreOperationImpl.java @@ -66,7 +66,7 @@ assert getState() == OperationState.READING : "Read ``" + line + "'' when in " + getState() + " state"; /* ENABLE_REPLICATION if */ if (hasSwitchedOver(line)) { - receivedMoveOperations(line); + prepareSwitchover(line); return; } /* ENABLE_REPLICATION end */ diff --git a/src/main/java/net/spy/memcached/protocol/ascii/CASOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/CASOperationImpl.java index 165ac5224..64a13afb0 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/CASOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/CASOperationImpl.java @@ -75,7 +75,7 @@ assert getState() == OperationState.READING : "Read ``" + line + "'' when in " + getState() + " state"; /* ENABLE_REPLICATION if */ if (hasSwitchedOver(line)) { - receivedMoveOperations(line); + prepareSwitchover(line); return; } /* ENABLE_REPLICATION end */ diff --git a/src/main/java/net/spy/memcached/protocol/ascii/CollectionBulkInsertOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/CollectionBulkInsertOperationImpl.java index 418c6fcda..f4d454505 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/CollectionBulkInsertOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/CollectionBulkInsertOperationImpl.java @@ -91,7 +91,7 @@ assert getState() == OperationState.READING /* ENABLE_REPLICATION if */ if (hasSwitchedOver(line)) { this.insert.setNextOpIndex(index); - receivedMoveOperations(line); + prepareSwitchover(line); return; } /* ENABLE_REPLICATION end */ diff --git a/src/main/java/net/spy/memcached/protocol/ascii/CollectionCreateOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/CollectionCreateOperationImpl.java index 39e038f91..7254952f2 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/CollectionCreateOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/CollectionCreateOperationImpl.java @@ -79,7 +79,7 @@ assert getState() == OperationState.READING : "Read ``" + line + "'' when in " + getState() + " state"; /* ENABLE_REPLICATION if */ if (hasSwitchedOver(line)) { - receivedMoveOperations(line); + prepareSwitchover(line); return; } /* ENABLE_REPLICATION end */ diff --git a/src/main/java/net/spy/memcached/protocol/ascii/CollectionDeleteOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/CollectionDeleteOperationImpl.java index 963aadd6d..4e77d835c 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/CollectionDeleteOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/CollectionDeleteOperationImpl.java @@ -87,7 +87,7 @@ assert getState() == OperationState.READING : "Read ``" + line + "'' when in " + getState() + " state"; /* ENABLE_REPLICATION if */ if (hasSwitchedOver(line)) { - receivedMoveOperations(line); + prepareSwitchover(line); return; } /* ENABLE_REPLICATION end */ diff --git a/src/main/java/net/spy/memcached/protocol/ascii/CollectionGetOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/CollectionGetOperationImpl.java index 296fd736c..1aa9f8c27 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/CollectionGetOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/CollectionGetOperationImpl.java @@ -110,7 +110,7 @@ public CollectionGetOperationImpl(String key, CollectionGet collectionGet, public void handleLine(String line) { /* ENABLE_REPLICATION if */ if (hasSwitchedOver(line)) { - receivedMoveOperations(line); + prepareSwitchover(line); return; } /* ENABLE_REPLICATION end */ diff --git a/src/main/java/net/spy/memcached/protocol/ascii/CollectionInsertOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/CollectionInsertOperationImpl.java index 4f3b43595..17b229caa 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/CollectionInsertOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/CollectionInsertOperationImpl.java @@ -104,7 +104,7 @@ assert getState() == OperationState.READING : "Read ``" + line + "'' when in " + getState() + " state"; /* ENABLE_REPLICATION if */ if (hasSwitchedOver(line)) { - receivedMoveOperations(line); + prepareSwitchover(line); return; } /* ENABLE_REPLICATION end */ diff --git a/src/main/java/net/spy/memcached/protocol/ascii/CollectionMutateOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/CollectionMutateOperationImpl.java index 04c3360d8..21272eedf 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/CollectionMutateOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/CollectionMutateOperationImpl.java @@ -82,7 +82,7 @@ public void handleLine(String line) { /* ENABLE_REPLICATION if */ if (hasSwitchedOver(line)) { - receivedMoveOperations(line); + prepareSwitchover(line); return; } /* ENABLE_REPLICATION end */ diff --git a/src/main/java/net/spy/memcached/protocol/ascii/CollectionPipedInsertOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/CollectionPipedInsertOperationImpl.java index 44dd41130..e472f7e8a 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/CollectionPipedInsertOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/CollectionPipedInsertOperationImpl.java @@ -98,7 +98,7 @@ assert getState() == OperationState.READING /* ENABLE_REPLICATION if */ if (hasSwitchedOver(line)) { this.insert.setNextOpIndex(index); - receivedMoveOperations(line); + prepareSwitchover(line); return; } /* ENABLE_REPLICATION end */ diff --git a/src/main/java/net/spy/memcached/protocol/ascii/CollectionPipedUpdateOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/CollectionPipedUpdateOperationImpl.java index 0a45ce7ff..a9859097d 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/CollectionPipedUpdateOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/CollectionPipedUpdateOperationImpl.java @@ -92,7 +92,7 @@ assert getState() == OperationState.READING : "Read ``" + line /* ENABLE_REPLICATION if */ if (hasSwitchedOver(line)) { this.update.setNextOpIndex(index); - receivedMoveOperations(line); + prepareSwitchover(line); return; } /* ENABLE_REPLICATION end */ diff --git a/src/main/java/net/spy/memcached/protocol/ascii/CollectionUpdateOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/CollectionUpdateOperationImpl.java index 39c966d3b..05337b8cb 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/CollectionUpdateOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/CollectionUpdateOperationImpl.java @@ -89,7 +89,7 @@ assert getState() == OperationState.READING : "Read ``" + line + "'' when in " + getState() + " state"; /* ENABLE_REPLICATION if */ if (hasSwitchedOver(line)) { - receivedMoveOperations(line); + prepareSwitchover(line); return; } /* ENABLE_REPLICATION end */ diff --git a/src/main/java/net/spy/memcached/protocol/ascii/DeleteOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/DeleteOperationImpl.java index 8836e1707..28c1e4fd4 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/DeleteOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/DeleteOperationImpl.java @@ -60,7 +60,7 @@ public void handleLine(String line) { getLogger().debug("Delete of %s returned %s", key, line); /* ENABLE_REPLICATION if */ if (hasSwitchedOver(line)) { - receivedMoveOperations(line); + prepareSwitchover(line); return; } /* ENABLE_REPLICATION end */ diff --git a/src/main/java/net/spy/memcached/protocol/ascii/FlushByPrefixOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/FlushByPrefixOperationImpl.java index 5cea575f3..b5fe16c84 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/FlushByPrefixOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/FlushByPrefixOperationImpl.java @@ -58,7 +58,7 @@ public void handleLine(String line) { getLogger().debug("Flush completed successfully"); /* ENABLE_REPLICATION if */ if (hasSwitchedOver(line)) { - receivedMoveOperations(line); + prepareSwitchover(line); return; } /* ENABLE_REPLICATION end */ diff --git a/src/main/java/net/spy/memcached/protocol/ascii/FlushOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/FlushOperationImpl.java index 636c50ab7..e1414cd53 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/FlushOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/FlushOperationImpl.java @@ -55,7 +55,7 @@ public void handleLine(String line) { getLogger().debug("Flush completed successfully"); /* ENABLE_REPLICATION if */ if (hasSwitchedOver(line)) { - receivedMoveOperations(line); + prepareSwitchover(line); return; } /* ENABLE_REPLICATION end */ diff --git a/src/main/java/net/spy/memcached/protocol/ascii/MutatorOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/MutatorOperationImpl.java index 648fc53d5..1b0e45e8e 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/MutatorOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/MutatorOperationImpl.java @@ -73,7 +73,7 @@ public MutatorOperationImpl(Mutator m, String k, int amt, long d, int e, public void handleLine(String line) { /* ENABLE_REPLICATION if */ if (hasSwitchedOver(line)) { - receivedMoveOperations(line); + prepareSwitchover(line); return; } /* ENABLE_REPLICATION end */ diff --git a/src/main/java/net/spy/memcached/protocol/ascii/OperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/OperationImpl.java index 4c67ebf59..37a8d7723 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/OperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/OperationImpl.java @@ -145,7 +145,7 @@ public void readFromBuffer(ByteBuffer data) throws IOException { // Loop while there's data remaining to get it all drained. while (data.remaining() > 0) { if (getState() == OperationState.COMPLETE || - getState() == OperationState.MOVING || // ENABLE_REPLICATION + getState() == OperationState.NEED_SWITCHOVER || // ENABLE_REPLICATION getState() == OperationState.REDIRECT) { // ENABLE_MIGRATION return; } diff --git a/src/main/java/net/spy/memcached/protocol/ascii/SetAttrOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/SetAttrOperationImpl.java index 061654947..95b2460ee 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/SetAttrOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/SetAttrOperationImpl.java @@ -73,7 +73,7 @@ assert getState() == OperationState.READING : "Read ``" + line + "'' when in " + getState() + " state"; /* ENABLE_REPLICATION if */ if (hasSwitchedOver(line)) { - receivedMoveOperations(line); + prepareSwitchover(line); return; } /* ENABLE_REPLICATION end */