Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INTERNAL: rename switchover method and state #855

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/net/spy/memcached/MemcachedConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/spy/memcached/ops/OperationState.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ip:port>", "REPL_SLAVE <ip:port>"
Expand All @@ -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 */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void handleLine(String line) {

/* ENABLE_REPLICATION if */
if (hasSwitchedOver(line)) {
receivedMoveOperations(line);
prepareSwitchover(line);
return;
}
/* ENABLE_REPLICATION end */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void handleLine(String line) {

/* ENABLE_REPLICATION if */
if (hasSwitchedOver(line)) {
receivedMoveOperations(line);
prepareSwitchover(line);
return;
}
/* ENABLE_REPLICATION end */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down