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

Wait for parked backup execution in vector optimization tests [AI-192] #2251

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@ public void delete() {
public void optimize() throws ExecutionException, InterruptedException {
var start = System.currentTimeMillis();

// TODO: this may fail with > 1 client
// TODO: this will cause redundant invocations with >1 client
var cleanupTimer = withTimer(() -> collection.optimizeAsync().toCompletableFuture().join());

if (backupCount + asyncBackupCount > 0) {
// optimize backups are async - wait for them also to get true time
// optimize backups are async and blocking (can be parked) - wait for them also to get true time
HazelcastUtils.waitForClusterSafeState(targetInstance);
HazelcastUtils.waitForNoParkedOperations(targetInstance);
var cleanupTotalTimer = System.currentTimeMillis() - start;
logger.info("Cleanup primary time: {} ms", cleanupTimer);
logger.info("Cleanup wait for backups time: {} ms", cleanupTotalTimer -cleanupTimer);
logger.info("Cleanup wait for backups time: {} ms", cleanupTotalTimer - cleanupTimer);
logger.info("Cleanup total time: {} ms", cleanupTotalTimer);
} else {
logger.info("Cleanup time: {} ms", cleanupTimer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import com.hazelcast.config.Config;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.HazelcastInstanceAware;
import com.hazelcast.instance.impl.HazelcastInstanceImpl;
import com.hazelcast.shaded.org.json.JSONArray;
import com.hazelcast.shaded.org.json.JSONObject;
import com.hazelcast.spi.impl.operationparker.impl.OperationParkerImpl;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -128,6 +130,13 @@ public static void waitForClusterSafeState(HazelcastInstance targetInstance) thr
targetInstance.getExecutorService("safe-check").submit(new WaitForClusterSafe()).get();
}

public static void waitForNoParkedOperations(HazelcastInstance targetInstance) throws InterruptedException, ExecutionException {
var futures = targetInstance.getExecutorService("safe-check").submitToAllMembers(new WaitForNoParkedOperations());
for (var future : futures.values()) {
future.get();
}
}

private static class WaitForClusterSafe implements Callable<Boolean>, HazelcastInstanceAware, Serializable {
private HazelcastInstance node;

Expand All @@ -144,4 +153,22 @@ public void setHazelcastInstance(HazelcastInstance node) {
this.node = node;
}
}

private static class WaitForNoParkedOperations implements Callable<Boolean>, HazelcastInstanceAware, Serializable {
private HazelcastInstance node;

@Override
public Boolean call() throws Exception {
OperationParkerImpl parker = (OperationParkerImpl) ((HazelcastInstanceImpl) node).node.getNodeEngine().getOperationParker();
while (parker.getTotalValidWaitingOperationCount() > 0) {
Thread.sleep(1);
}
return true;
}

@Override
public void setHazelcastInstance(HazelcastInstance node) {
this.node = node;
}
}
}