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

feat: print describe before leader election #167

Merged
merged 4 commits into from
Nov 14, 2024
Merged
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 @@ -16,6 +16,7 @@
import tech.ydb.coordination.CoordinationSession;
import tech.ydb.coordination.SemaphoreLease;
import tech.ydb.coordination.settings.CoordinationSessionSettings;
import tech.ydb.coordination.settings.DescribeSemaphoreMode;
import tech.ydb.core.Result;
import tech.ydb.jdbc.YdbConnection;

Expand Down Expand Up @@ -64,12 +65,27 @@ public Optional<SimpleLock> lock(LockConfiguration lockConfiguration) {
var statusCS = coordinationSession.connect().join();

if (!statusCS.isSuccess()) {
logger.info("Failed creating coordination session [{}]", coordinationSession);
logger.warn("Failed creating coordination session [{}]", coordinationSession);

return Optional.empty();
}

logger.info("Created coordination node session [{}]", coordinationSession);
logger.debug("Created coordination node session [{}]", coordinationSession);

var describeResult = coordinationSession.describeSemaphore(
lockConfiguration.getName(),
DescribeSemaphoreMode.WITH_OWNERS
).join();

if (describeResult.isSuccess()) {
var describe = describeResult.getValue();

if (!describe.getOwnersList().isEmpty()) {
var describePayload = new String(describe.getOwnersList().get(0).getData(), StandardCharsets.UTF_8);

logger.info("Received DescribeSemaphore[Name={}, Data={}]", describe.getName(), describePayload);
}
}

Result<SemaphoreLease> semaphoreLease = coordinationSession.acquireEphemeralSemaphore(
lockConfiguration.getName(),
Expand All @@ -81,12 +97,12 @@ public Optional<SimpleLock> lock(LockConfiguration lockConfiguration) {
logger.debug(coordinationSession.toString());

if (semaphoreLease.isSuccess()) {
logger.info("Instance[{}] acquired semaphore[SemaphoreName={}]", instanceInfo,
logger.debug("Instance[{}] acquired semaphore [SemaphoreName={}]", instanceInfo,
semaphoreLease.getValue().getSemaphoreName());

return Optional.of(new YdbSimpleLock(semaphoreLease.getValue(), instanceInfo, coordinationSession));
} else {
logger.info("Instance[{}] did not acquire semaphore", instanceInfo);
logger.debug("Instance[{}] did not acquire semaphore", instanceInfo);

return Optional.empty();
}
Expand All @@ -96,7 +112,7 @@ private record YdbSimpleLock(SemaphoreLease semaphoreLease, String metaInfo,
CoordinationSession coordinationSession) implements SimpleLock {
@Override
public void unlock() {
logger.info("Instance[{}] released semaphore[SemaphoreName={}]", metaInfo, semaphoreLease.getSemaphoreName());
logger.info("Instance[{}] released semaphore [SemaphoreName={}]", metaInfo, semaphoreLease.getSemaphoreName());

semaphoreLease.release().join();

Expand Down