You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by "rdhabalia (via GitHub)" <gi...@apache.org> on 2023/04/17 06:04:23 UTC
[GitHub] [bookkeeper] rdhabalia opened a new pull request, #3924: [stats][bookie] Add bookie sanity test metrics
rdhabalia opened a new pull request, #3924:
URL: https://github.com/apache/bookkeeper/pull/3924
### Motivation
It solves #3923
Right now, Bookie metrics (Prometheus) don't show if Bookie's sanity is passing or not. and with container-based Prometheus bookie metrics which are used for monitoring, it will be really useful if metrics also show the bookie sanity state so, Prometheus can automatically scrape the bookie sanity state and one can set up monitoring on it.
Therefore, add support to include the bookie sanity state in the bookie metrics.
For example:
```
URL: http://localhost:8000/metrics
:
# 1 shows bookie sanity is passing, 0 failed, -1 unknown
bookie_SERVER_SANITY 1
```
### Changes
- Add periodic task which performs sanity command on bookie and captures bookie sanity test periodically
- Reuse the `SanityTestCommnad` for this purpose but SanityTestCommand has lot of blocking IO which can cause thread blocking for metrics collection.
- Therefore, implement async method into `SanityTestCommnad` to avoid thread blocking and use it in metrics collection.
Master Issue: #3923
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] horizonzy commented on a diff in pull request #3924: [stats][bookie] Add bookie sanity test metrics
Posted by "horizonzy (via GitHub)" <gi...@apache.org>.
horizonzy commented on code in PR #3924:
URL: https://github.com/apache/bookkeeper/pull/3924#discussion_r1285727610
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieStateManager.java:
##########
@@ -149,6 +160,30 @@ public Number getSample() {
}
};
statsLogger.registerGauge(SERVER_STATUS, serverStatusGauge);
+ this.serverSanityGauge = new Gauge<Number>() {
+ @Override
+ public Number getDefaultValue() {
+ return -1;
+ }
+
+ @Override
+ public Number getSample() {
+ return sanityPassed.get();
+ }
+ };
+ statsLogger.registerGauge(SERVER_SANITY, serverSanityGauge);
+ stateService.scheduleAtFixedRate(() -> {
+ if (isReadOnly()) {
+ sanityPassed.set(1);
+ return;
+ }
+ SanityTestCommand.handleAsync(conf, new SanityTestCommand.SanityFlags()).thenAccept(__ -> {
Review Comment:
It looks like the config `sanityCheckMetricsEnabled` doesn't work. The scheduled task only works when `sanityCheckMetricsEnabled` is `true`.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] rdhabalia commented on pull request #3924: [stats][bookie] Add bookie sanity test metrics
Posted by "rdhabalia (via GitHub)" <gi...@apache.org>.
rdhabalia commented on PR #3924:
URL: https://github.com/apache/bookkeeper/pull/3924#issuecomment-1513690055
@hangc0276 comments are addressed. can you please merge if it looks good to you.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] rdhabalia commented on a diff in pull request #3924: [stats][bookie] Add bookie sanity test metrics
Posted by "rdhabalia (via GitHub)" <gi...@apache.org>.
rdhabalia commented on code in PR #3924:
URL: https://github.com/apache/bookkeeper/pull/3924#discussion_r1170369955
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/bookie/SanityTestCommand.java:
##########
@@ -81,59 +86,126 @@ public boolean apply(ServerConfiguration conf, SanityFlags cmdFlags) {
}
}
- private boolean handle(ServerConfiguration conf, SanityFlags cmdFlags) throws Exception {
+ private static boolean handle(ServerConfiguration conf, SanityFlags cmdFlags) throws Exception {
+ try {
+ return handleAsync(conf, cmdFlags).get();
+ } catch (Exception e) {
+ LOG.warn("Error in bookie sanity test", e);
+ return false;
+ }
+ }
+
+ public static CompletableFuture<Boolean> handleAsync(ServerConfiguration conf, SanityFlags cmdFlags) {
+ CompletableFuture<Boolean> result = new CompletableFuture<Boolean>();
ClientConfiguration clientConf = new ClientConfiguration();
clientConf.addConfiguration(conf);
clientConf.setEnsemblePlacementPolicy(LocalBookieEnsemblePlacementPolicy.class);
clientConf.setAddEntryTimeout(cmdFlags.timeout);
clientConf.setReadEntryTimeout(cmdFlags.timeout);
- BookKeeper bk = new BookKeeper(clientConf);
- LedgerHandle lh = null;
+ BookKeeper bk;
try {
- lh = bk.createLedger(1, 1, BookKeeper.DigestType.MAC, new byte[0]);
- LOG.info("Create ledger {}", lh.getId());
+ bk = new BookKeeper(clientConf);
+ } catch (BKException | IOException | InterruptedException e) {
+ LOG.warn("Failed to initialize bookkeeper client", e);
+ result.completeExceptionally(e);
+ return result;
+ }
+ bk.asyncCreateLedger(1, 1, BookKeeper.DigestType.MAC, new byte[0], (rc, lh, ctx) -> {
+ if (rc != BKException.Code.OK) {
+ LOG.warn("ledger creation failed for sanity command {}", rc);
+ result.completeExceptionally(BKException.create(rc));
+ return;
+ }
+ List<CompletableFuture<Void>> entriesFutures = new ArrayList<>();
for (int i = 0; i < cmdFlags.entries; i++) {
String content = "entry-" + i;
- lh.addEntry(content.getBytes(UTF_8));
- }
-
- LOG.info("Written {} entries in ledger {}", cmdFlags.entries, lh.getId());
-
- // Reopen the ledger and read entries
- lh = bk.openLedger(lh.getId(), BookKeeper.DigestType.MAC, new byte[0]);
- if (lh.getLastAddConfirmed() != (cmdFlags.entries - 1)) {
- throw new Exception("Invalid last entry found on ledger. expecting: " + (cmdFlags.entries - 1)
- + " -- found: " + lh.getLastAddConfirmed());
+ CompletableFuture<Void> entryFuture = new CompletableFuture<>();
+ entriesFutures.add(entryFuture);
+ lh.asyncAddEntry(content.getBytes(UTF_8), (arc, alh, entryId, actx) -> {
+ if (arc != BKException.Code.OK) {
+ LOG.warn("ledger add entry failed for {}-{}", alh.getId(), arc);
+ entryFuture.completeExceptionally(BKException.create(arc));
+ return;
+ }
+ entryFuture.complete(null);
+ }, null);
}
+ CompletableFuture<LedgerHandle> lhFuture = new CompletableFuture<>();
+ CompletableFuture<Void> readEntryFuture = new CompletableFuture<>();
+
+ FutureUtils.collect(entriesFutures).thenCompose(_r -> {
+ bk.asyncOpenLedger(lh.getId(), BookKeeper.DigestType.MAC, new byte[0], (orc, olh, octx) -> {
+ if (orc != BKException.Code.OK) {
+ LOG.warn("open sanity ledger failed for {}-{}", lh.getId(), orc);
+ lhFuture.completeExceptionally(BKException.create(orc));
+ return;
+ }
+ long lac = olh.getLastAddConfirmed();
+ if (lac != (cmdFlags.entries - 1)) {
+ lhFuture.completeExceptionally(new Exception("Invalid last entry found on ledger. expecting: "
+ + (cmdFlags.entries - 1) + " -- found: " + lac));
+ return;
+ }
+ lhFuture.complete(lh);
+ }, null);
Review Comment:
well running sanity is executing one operation of what bookie suppose to do with high throughput : creating ledger/add entries/read entries/delete ledger. so, one operation per minute should be fine. the only thing is we should not have any blocking IO and that's the reason, I have changed sanityTestCommand implementation with async behavior.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] rdhabalia commented on a diff in pull request #3924: [stats][bookie] Add bookie sanity test metrics
Posted by "rdhabalia (via GitHub)" <gi...@apache.org>.
rdhabalia commented on code in PR #3924:
URL: https://github.com/apache/bookkeeper/pull/3924#discussion_r1169471144
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/bookie/SanityTestCommand.java:
##########
@@ -81,59 +86,126 @@ public boolean apply(ServerConfiguration conf, SanityFlags cmdFlags) {
}
}
- private boolean handle(ServerConfiguration conf, SanityFlags cmdFlags) throws Exception {
+ private static boolean handle(ServerConfiguration conf, SanityFlags cmdFlags) throws Exception {
+ try {
+ return handleAsync(conf, cmdFlags).get();
+ } catch (Exception e) {
+ LOG.warn("Error in bookie sanity test", e);
+ return false;
+ }
+ }
+
+ public static CompletableFuture<Boolean> handleAsync(ServerConfiguration conf, SanityFlags cmdFlags) {
+ CompletableFuture<Boolean> result = new CompletableFuture<Boolean>();
ClientConfiguration clientConf = new ClientConfiguration();
clientConf.addConfiguration(conf);
clientConf.setEnsemblePlacementPolicy(LocalBookieEnsemblePlacementPolicy.class);
clientConf.setAddEntryTimeout(cmdFlags.timeout);
clientConf.setReadEntryTimeout(cmdFlags.timeout);
- BookKeeper bk = new BookKeeper(clientConf);
- LedgerHandle lh = null;
+ BookKeeper bk;
try {
- lh = bk.createLedger(1, 1, BookKeeper.DigestType.MAC, new byte[0]);
- LOG.info("Create ledger {}", lh.getId());
+ bk = new BookKeeper(clientConf);
+ } catch (BKException | IOException | InterruptedException e) {
+ LOG.warn("Failed to initialize bookkeeper client", e);
+ result.completeExceptionally(e);
+ return result;
+ }
+ bk.asyncCreateLedger(1, 1, BookKeeper.DigestType.MAC, new byte[0], (rc, lh, ctx) -> {
+ if (rc != BKException.Code.OK) {
+ LOG.warn("ledger creation failed for sanity command {}", rc);
+ result.completeExceptionally(BKException.create(rc));
+ return;
+ }
+ List<CompletableFuture<Void>> entriesFutures = new ArrayList<>();
for (int i = 0; i < cmdFlags.entries; i++) {
String content = "entry-" + i;
- lh.addEntry(content.getBytes(UTF_8));
- }
-
- LOG.info("Written {} entries in ledger {}", cmdFlags.entries, lh.getId());
-
- // Reopen the ledger and read entries
- lh = bk.openLedger(lh.getId(), BookKeeper.DigestType.MAC, new byte[0]);
- if (lh.getLastAddConfirmed() != (cmdFlags.entries - 1)) {
- throw new Exception("Invalid last entry found on ledger. expecting: " + (cmdFlags.entries - 1)
- + " -- found: " + lh.getLastAddConfirmed());
+ CompletableFuture<Void> entryFuture = new CompletableFuture<>();
+ entriesFutures.add(entryFuture);
+ lh.asyncAddEntry(content.getBytes(UTF_8), (arc, alh, entryId, actx) -> {
+ if (arc != BKException.Code.OK) {
+ LOG.warn("ledger add entry failed for {}-{}", alh.getId(), arc);
+ entryFuture.completeExceptionally(BKException.create(arc));
+ return;
+ }
+ entryFuture.complete(null);
+ }, null);
}
+ CompletableFuture<LedgerHandle> lhFuture = new CompletableFuture<>();
+ CompletableFuture<Void> readEntryFuture = new CompletableFuture<>();
+
+ FutureUtils.collect(entriesFutures).thenCompose(_r -> {
+ bk.asyncOpenLedger(lh.getId(), BookKeeper.DigestType.MAC, new byte[0], (orc, olh, octx) -> {
+ if (orc != BKException.Code.OK) {
+ LOG.warn("open sanity ledger failed for {}-{}", lh.getId(), orc);
+ lhFuture.completeExceptionally(BKException.create(orc));
+ return;
+ }
+ long lac = olh.getLastAddConfirmed();
+ if (lac != (cmdFlags.entries - 1)) {
+ lhFuture.completeExceptionally(new Exception("Invalid last entry found on ledger. expecting: "
+ + (cmdFlags.entries - 1) + " -- found: " + lac));
+ return;
+ }
+ lhFuture.complete(lh);
+ }, null);
Review Comment:
this is existing code where we don't have handling for failed delete. this change only changes blocking IO to async to avoid thread-blocking while checking sanity.
So, if we need any enhancement into existing codebase then we can address it in separate PR.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] rdhabalia commented on a diff in pull request #3924: [stats][bookie] Add bookie sanity test metrics
Posted by "rdhabalia (via GitHub)" <gi...@apache.org>.
rdhabalia commented on code in PR #3924:
URL: https://github.com/apache/bookkeeper/pull/3924#discussion_r1170381331
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieStateManager.java:
##########
@@ -149,6 +160,30 @@ public Number getSample() {
}
};
statsLogger.registerGauge(SERVER_STATUS, serverStatusGauge);
+ this.serverSanityGauge = new Gauge<Number>() {
+ @Override
+ public Number getDefaultValue() {
+ return -1;
+ }
+
+ @Override
+ public Number getSample() {
+ return sanityPassed.get();
+ }
+ };
+ statsLogger.registerGauge(SERVER_SANITY, serverSanityGauge);
+ stateService.scheduleAtFixedRate(() -> {
+ if (forceReadOnly.get()) {
+ sanityPassed.set(1);
+ return;
+ }
+ SanityTestCommand.handleAsync(conf, new SanityTestCommand.SanityFlags()).thenAccept(__ -> {
Review Comment:
i see. sure, let me add readOnly check as well.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] hangc0276 commented on a diff in pull request #3924: [stats][bookie] Add bookie sanity test metrics
Posted by "hangc0276 (via GitHub)" <gi...@apache.org>.
hangc0276 commented on code in PR #3924:
URL: https://github.com/apache/bookkeeper/pull/3924#discussion_r1170697981
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieStateManager.java:
##########
@@ -149,6 +160,30 @@ public Number getSample() {
}
};
statsLogger.registerGauge(SERVER_STATUS, serverStatusGauge);
+ this.serverSanityGauge = new Gauge<Number>() {
+ @Override
+ public Number getDefaultValue() {
+ return -1;
+ }
+
+ @Override
+ public Number getSample() {
+ return sanityPassed.get();
+ }
+ };
+ statsLogger.registerGauge(SERVER_SANITY, serverSanityGauge);
+ stateService.scheduleAtFixedRate(() -> {
+ if (forceReadOnly.get()) {
+ sanityPassed.set(1);
+ return;
+ }
+ SanityTestCommand.handleAsync(conf, new SanityTestCommand.SanityFlags()).thenAccept(__ -> {
Review Comment:
You can call `isReadOnly()` directly
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] hangc0276 merged pull request #3924: [stats][bookie] Add bookie sanity test metrics
Posted by "hangc0276 (via GitHub)" <gi...@apache.org>.
hangc0276 merged PR #3924:
URL: https://github.com/apache/bookkeeper/pull/3924
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] hangc0276 commented on a diff in pull request #3924: [stats][bookie] Add bookie sanity test metrics
Posted by "hangc0276 (via GitHub)" <gi...@apache.org>.
hangc0276 commented on code in PR #3924:
URL: https://github.com/apache/bookkeeper/pull/3924#discussion_r1169448534
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieStateManager.java:
##########
@@ -149,6 +160,30 @@ public Number getSample() {
}
};
statsLogger.registerGauge(SERVER_STATUS, serverStatusGauge);
+ this.serverSanityGauge = new Gauge<Number>() {
+ @Override
+ public Number getDefaultValue() {
+ return -1;
+ }
+
+ @Override
+ public Number getSample() {
+ return sanityPassed.get();
+ }
+ };
+ statsLogger.registerGauge(SERVER_SANITY, serverSanityGauge);
+ stateService.scheduleAtFixedRate(() -> {
+ if (forceReadOnly.get()) {
+ sanityPassed.set(1);
+ return;
+ }
+ SanityTestCommand.handleAsync(conf, new SanityTestCommand.SanityFlags()).thenAccept(__ -> {
Review Comment:
Do we need to check whether the bookie is in ReadOnly mode? so that we can skip running the Sanity test.
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/bookie/SanityTestCommand.java:
##########
@@ -81,59 +86,126 @@ public boolean apply(ServerConfiguration conf, SanityFlags cmdFlags) {
}
}
- private boolean handle(ServerConfiguration conf, SanityFlags cmdFlags) throws Exception {
+ private static boolean handle(ServerConfiguration conf, SanityFlags cmdFlags) throws Exception {
+ try {
+ return handleAsync(conf, cmdFlags).get();
+ } catch (Exception e) {
+ LOG.warn("Error in bookie sanity test", e);
+ return false;
+ }
+ }
+
+ public static CompletableFuture<Boolean> handleAsync(ServerConfiguration conf, SanityFlags cmdFlags) {
+ CompletableFuture<Boolean> result = new CompletableFuture<Boolean>();
ClientConfiguration clientConf = new ClientConfiguration();
clientConf.addConfiguration(conf);
clientConf.setEnsemblePlacementPolicy(LocalBookieEnsemblePlacementPolicy.class);
clientConf.setAddEntryTimeout(cmdFlags.timeout);
clientConf.setReadEntryTimeout(cmdFlags.timeout);
- BookKeeper bk = new BookKeeper(clientConf);
- LedgerHandle lh = null;
+ BookKeeper bk;
try {
- lh = bk.createLedger(1, 1, BookKeeper.DigestType.MAC, new byte[0]);
- LOG.info("Create ledger {}", lh.getId());
+ bk = new BookKeeper(clientConf);
+ } catch (BKException | IOException | InterruptedException e) {
+ LOG.warn("Failed to initialize bookkeeper client", e);
+ result.completeExceptionally(e);
+ return result;
+ }
+ bk.asyncCreateLedger(1, 1, BookKeeper.DigestType.MAC, new byte[0], (rc, lh, ctx) -> {
+ if (rc != BKException.Code.OK) {
+ LOG.warn("ledger creation failed for sanity command {}", rc);
+ result.completeExceptionally(BKException.create(rc));
+ return;
+ }
+ List<CompletableFuture<Void>> entriesFutures = new ArrayList<>();
for (int i = 0; i < cmdFlags.entries; i++) {
String content = "entry-" + i;
- lh.addEntry(content.getBytes(UTF_8));
- }
-
- LOG.info("Written {} entries in ledger {}", cmdFlags.entries, lh.getId());
-
- // Reopen the ledger and read entries
- lh = bk.openLedger(lh.getId(), BookKeeper.DigestType.MAC, new byte[0]);
- if (lh.getLastAddConfirmed() != (cmdFlags.entries - 1)) {
- throw new Exception("Invalid last entry found on ledger. expecting: " + (cmdFlags.entries - 1)
- + " -- found: " + lh.getLastAddConfirmed());
+ CompletableFuture<Void> entryFuture = new CompletableFuture<>();
+ entriesFutures.add(entryFuture);
+ lh.asyncAddEntry(content.getBytes(UTF_8), (arc, alh, entryId, actx) -> {
+ if (arc != BKException.Code.OK) {
+ LOG.warn("ledger add entry failed for {}-{}", alh.getId(), arc);
+ entryFuture.completeExceptionally(BKException.create(arc));
+ return;
+ }
+ entryFuture.complete(null);
+ }, null);
}
+ CompletableFuture<LedgerHandle> lhFuture = new CompletableFuture<>();
+ CompletableFuture<Void> readEntryFuture = new CompletableFuture<>();
+
+ FutureUtils.collect(entriesFutures).thenCompose(_r -> {
+ bk.asyncOpenLedger(lh.getId(), BookKeeper.DigestType.MAC, new byte[0], (orc, olh, octx) -> {
+ if (orc != BKException.Code.OK) {
+ LOG.warn("open sanity ledger failed for {}-{}", lh.getId(), orc);
+ lhFuture.completeExceptionally(BKException.create(orc));
+ return;
+ }
+ long lac = olh.getLastAddConfirmed();
+ if (lac != (cmdFlags.entries - 1)) {
+ lhFuture.completeExceptionally(new Exception("Invalid last entry found on ledger. expecting: "
+ + (cmdFlags.entries - 1) + " -- found: " + lac));
+ return;
+ }
+ lhFuture.complete(lh);
+ }, null);
Review Comment:
We'd better add the `customMetadata` for the created ledger in order to find out orphan ledgers if the ledger delete failed.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] rdhabalia commented on a diff in pull request #3924: [stats][bookie] Add bookie sanity test metrics
Posted by "rdhabalia (via GitHub)" <gi...@apache.org>.
rdhabalia commented on code in PR #3924:
URL: https://github.com/apache/bookkeeper/pull/3924#discussion_r1169471486
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieStateManager.java:
##########
@@ -149,6 +160,30 @@ public Number getSample() {
}
};
statsLogger.registerGauge(SERVER_STATUS, serverStatusGauge);
+ this.serverSanityGauge = new Gauge<Number>() {
+ @Override
+ public Number getDefaultValue() {
+ return -1;
+ }
+
+ @Override
+ public Number getSample() {
+ return sanityPassed.get();
+ }
+ };
+ statsLogger.registerGauge(SERVER_SANITY, serverSanityGauge);
+ stateService.scheduleAtFixedRate(() -> {
+ if (forceReadOnly.get()) {
+ sanityPassed.set(1);
+ return;
+ }
+ SanityTestCommand.handleAsync(conf, new SanityTestCommand.SanityFlags()).thenAccept(__ -> {
Review Comment:
yes, it's checking at line#176
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] hangc0276 commented on a diff in pull request #3924: [stats][bookie] Add bookie sanity test metrics
Posted by "hangc0276 (via GitHub)" <gi...@apache.org>.
hangc0276 commented on code in PR #3924:
URL: https://github.com/apache/bookkeeper/pull/3924#discussion_r1169633865
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieStateManager.java:
##########
@@ -149,6 +160,30 @@ public Number getSample() {
}
};
statsLogger.registerGauge(SERVER_STATUS, serverStatusGauge);
+ this.serverSanityGauge = new Gauge<Number>() {
+ @Override
+ public Number getDefaultValue() {
+ return -1;
+ }
+
+ @Override
+ public Number getSample() {
+ return sanityPassed.get();
+ }
+ };
+ statsLogger.registerGauge(SERVER_SANITY, serverSanityGauge);
+ stateService.scheduleAtFixedRate(() -> {
+ if (forceReadOnly.get()) {
+ sanityPassed.set(1);
+ return;
+ }
+ SanityTestCommand.handleAsync(conf, new SanityTestCommand.SanityFlags()).thenAccept(__ -> {
Review Comment:
Line #176 only checks forceReadOnly, not check the bookie runs into ReadOnly due to the disk being full.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] rdhabalia commented on a diff in pull request #3924: [stats][bookie] Add bookie sanity test metrics
Posted by "rdhabalia (via GitHub)" <gi...@apache.org>.
rdhabalia commented on code in PR #3924:
URL: https://github.com/apache/bookkeeper/pull/3924#discussion_r1170705056
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieStateManager.java:
##########
@@ -149,6 +160,30 @@ public Number getSample() {
}
};
statsLogger.registerGauge(SERVER_STATUS, serverStatusGauge);
+ this.serverSanityGauge = new Gauge<Number>() {
+ @Override
+ public Number getDefaultValue() {
+ return -1;
+ }
+
+ @Override
+ public Number getSample() {
+ return sanityPassed.get();
+ }
+ };
+ statsLogger.registerGauge(SERVER_SANITY, serverSanityGauge);
+ stateService.scheduleAtFixedRate(() -> {
+ if (forceReadOnly.get()) {
+ sanityPassed.set(1);
+ return;
+ }
+ SanityTestCommand.handleAsync(conf, new SanityTestCommand.SanityFlags()).thenAccept(__ -> {
Review Comment:
sure, done.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] hangc0276 commented on a diff in pull request #3924: [stats][bookie] Add bookie sanity test metrics
Posted by "hangc0276 (via GitHub)" <gi...@apache.org>.
hangc0276 commented on code in PR #3924:
URL: https://github.com/apache/bookkeeper/pull/3924#discussion_r1169635388
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/bookie/SanityTestCommand.java:
##########
@@ -81,59 +86,126 @@ public boolean apply(ServerConfiguration conf, SanityFlags cmdFlags) {
}
}
- private boolean handle(ServerConfiguration conf, SanityFlags cmdFlags) throws Exception {
+ private static boolean handle(ServerConfiguration conf, SanityFlags cmdFlags) throws Exception {
+ try {
+ return handleAsync(conf, cmdFlags).get();
+ } catch (Exception e) {
+ LOG.warn("Error in bookie sanity test", e);
+ return false;
+ }
+ }
+
+ public static CompletableFuture<Boolean> handleAsync(ServerConfiguration conf, SanityFlags cmdFlags) {
+ CompletableFuture<Boolean> result = new CompletableFuture<Boolean>();
ClientConfiguration clientConf = new ClientConfiguration();
clientConf.addConfiguration(conf);
clientConf.setEnsemblePlacementPolicy(LocalBookieEnsemblePlacementPolicy.class);
clientConf.setAddEntryTimeout(cmdFlags.timeout);
clientConf.setReadEntryTimeout(cmdFlags.timeout);
- BookKeeper bk = new BookKeeper(clientConf);
- LedgerHandle lh = null;
+ BookKeeper bk;
try {
- lh = bk.createLedger(1, 1, BookKeeper.DigestType.MAC, new byte[0]);
- LOG.info("Create ledger {}", lh.getId());
+ bk = new BookKeeper(clientConf);
+ } catch (BKException | IOException | InterruptedException e) {
+ LOG.warn("Failed to initialize bookkeeper client", e);
+ result.completeExceptionally(e);
+ return result;
+ }
+ bk.asyncCreateLedger(1, 1, BookKeeper.DigestType.MAC, new byte[0], (rc, lh, ctx) -> {
+ if (rc != BKException.Code.OK) {
+ LOG.warn("ledger creation failed for sanity command {}", rc);
+ result.completeExceptionally(BKException.create(rc));
+ return;
+ }
+ List<CompletableFuture<Void>> entriesFutures = new ArrayList<>();
for (int i = 0; i < cmdFlags.entries; i++) {
String content = "entry-" + i;
- lh.addEntry(content.getBytes(UTF_8));
- }
-
- LOG.info("Written {} entries in ledger {}", cmdFlags.entries, lh.getId());
-
- // Reopen the ledger and read entries
- lh = bk.openLedger(lh.getId(), BookKeeper.DigestType.MAC, new byte[0]);
- if (lh.getLastAddConfirmed() != (cmdFlags.entries - 1)) {
- throw new Exception("Invalid last entry found on ledger. expecting: " + (cmdFlags.entries - 1)
- + " -- found: " + lh.getLastAddConfirmed());
+ CompletableFuture<Void> entryFuture = new CompletableFuture<>();
+ entriesFutures.add(entryFuture);
+ lh.asyncAddEntry(content.getBytes(UTF_8), (arc, alh, entryId, actx) -> {
+ if (arc != BKException.Code.OK) {
+ LOG.warn("ledger add entry failed for {}-{}", alh.getId(), arc);
+ entryFuture.completeExceptionally(BKException.create(arc));
+ return;
+ }
+ entryFuture.complete(null);
+ }, null);
}
+ CompletableFuture<LedgerHandle> lhFuture = new CompletableFuture<>();
+ CompletableFuture<Void> readEntryFuture = new CompletableFuture<>();
+
+ FutureUtils.collect(entriesFutures).thenCompose(_r -> {
+ bk.asyncOpenLedger(lh.getId(), BookKeeper.DigestType.MAC, new byte[0], (orc, olh, octx) -> {
+ if (orc != BKException.Code.OK) {
+ LOG.warn("open sanity ledger failed for {}-{}", lh.getId(), orc);
+ lhFuture.completeExceptionally(BKException.create(orc));
+ return;
+ }
+ long lac = olh.getLastAddConfirmed();
+ if (lac != (cmdFlags.entries - 1)) {
+ lhFuture.completeExceptionally(new Exception("Invalid last entry found on ledger. expecting: "
+ + (cmdFlags.entries - 1) + " -- found: " + lac));
+ return;
+ }
+ lhFuture.complete(lh);
+ }, null);
Review Comment:
This PR makes the case worse. The existing code only triggers the sanity test by the bookkeeper shell, but from this PR on, the bookie will trigger sanity test every 60s
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] rdhabalia commented on a diff in pull request #3924: [stats][bookie] Add bookie sanity test metrics
Posted by "rdhabalia (via GitHub)" <gi...@apache.org>.
rdhabalia commented on code in PR #3924:
URL: https://github.com/apache/bookkeeper/pull/3924#discussion_r1170441199
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/bookie/SanityTestCommand.java:
##########
@@ -81,59 +86,126 @@ public boolean apply(ServerConfiguration conf, SanityFlags cmdFlags) {
}
}
- private boolean handle(ServerConfiguration conf, SanityFlags cmdFlags) throws Exception {
+ private static boolean handle(ServerConfiguration conf, SanityFlags cmdFlags) throws Exception {
+ try {
+ return handleAsync(conf, cmdFlags).get();
+ } catch (Exception e) {
+ LOG.warn("Error in bookie sanity test", e);
+ return false;
+ }
+ }
+
+ public static CompletableFuture<Boolean> handleAsync(ServerConfiguration conf, SanityFlags cmdFlags) {
+ CompletableFuture<Boolean> result = new CompletableFuture<Boolean>();
ClientConfiguration clientConf = new ClientConfiguration();
clientConf.addConfiguration(conf);
clientConf.setEnsemblePlacementPolicy(LocalBookieEnsemblePlacementPolicy.class);
clientConf.setAddEntryTimeout(cmdFlags.timeout);
clientConf.setReadEntryTimeout(cmdFlags.timeout);
- BookKeeper bk = new BookKeeper(clientConf);
- LedgerHandle lh = null;
+ BookKeeper bk;
try {
- lh = bk.createLedger(1, 1, BookKeeper.DigestType.MAC, new byte[0]);
- LOG.info("Create ledger {}", lh.getId());
+ bk = new BookKeeper(clientConf);
+ } catch (BKException | IOException | InterruptedException e) {
+ LOG.warn("Failed to initialize bookkeeper client", e);
+ result.completeExceptionally(e);
+ return result;
+ }
+ bk.asyncCreateLedger(1, 1, BookKeeper.DigestType.MAC, new byte[0], (rc, lh, ctx) -> {
+ if (rc != BKException.Code.OK) {
+ LOG.warn("ledger creation failed for sanity command {}", rc);
+ result.completeExceptionally(BKException.create(rc));
+ return;
+ }
+ List<CompletableFuture<Void>> entriesFutures = new ArrayList<>();
for (int i = 0; i < cmdFlags.entries; i++) {
String content = "entry-" + i;
- lh.addEntry(content.getBytes(UTF_8));
- }
-
- LOG.info("Written {} entries in ledger {}", cmdFlags.entries, lh.getId());
-
- // Reopen the ledger and read entries
- lh = bk.openLedger(lh.getId(), BookKeeper.DigestType.MAC, new byte[0]);
- if (lh.getLastAddConfirmed() != (cmdFlags.entries - 1)) {
- throw new Exception("Invalid last entry found on ledger. expecting: " + (cmdFlags.entries - 1)
- + " -- found: " + lh.getLastAddConfirmed());
+ CompletableFuture<Void> entryFuture = new CompletableFuture<>();
+ entriesFutures.add(entryFuture);
+ lh.asyncAddEntry(content.getBytes(UTF_8), (arc, alh, entryId, actx) -> {
+ if (arc != BKException.Code.OK) {
+ LOG.warn("ledger add entry failed for {}-{}", alh.getId(), arc);
+ entryFuture.completeExceptionally(BKException.create(arc));
+ return;
+ }
+ entryFuture.complete(null);
+ }, null);
}
+ CompletableFuture<LedgerHandle> lhFuture = new CompletableFuture<>();
+ CompletableFuture<Void> readEntryFuture = new CompletableFuture<>();
+
+ FutureUtils.collect(entriesFutures).thenCompose(_r -> {
+ bk.asyncOpenLedger(lh.getId(), BookKeeper.DigestType.MAC, new byte[0], (orc, olh, octx) -> {
+ if (orc != BKException.Code.OK) {
+ LOG.warn("open sanity ledger failed for {}-{}", lh.getId(), orc);
+ lhFuture.completeExceptionally(BKException.create(orc));
+ return;
+ }
+ long lac = olh.getLastAddConfirmed();
+ if (lac != (cmdFlags.entries - 1)) {
+ lhFuture.completeExceptionally(new Exception("Invalid last entry found on ledger. expecting: "
+ + (cmdFlags.entries - 1) + " -- found: " + lac));
+ return;
+ }
+ lhFuture.complete(lh);
+ }, null);
Review Comment:
added the flag `sanityCheckMetricsEnabled` and disabled the behavior by default.
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieStateManager.java:
##########
@@ -149,6 +160,30 @@ public Number getSample() {
}
};
statsLogger.registerGauge(SERVER_STATUS, serverStatusGauge);
+ this.serverSanityGauge = new Gauge<Number>() {
+ @Override
+ public Number getDefaultValue() {
+ return -1;
+ }
+
+ @Override
+ public Number getSample() {
+ return sanityPassed.get();
+ }
+ };
+ statsLogger.registerGauge(SERVER_SANITY, serverSanityGauge);
+ stateService.scheduleAtFixedRate(() -> {
+ if (forceReadOnly.get()) {
+ sanityPassed.set(1);
+ return;
+ }
+ SanityTestCommand.handleAsync(conf, new SanityTestCommand.SanityFlags()).thenAccept(__ -> {
Review Comment:
done. added the read-only check.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] rdhabalia commented on a diff in pull request #3924: [stats][bookie] Add bookie sanity test metrics
Posted by "rdhabalia (via GitHub)" <gi...@apache.org>.
rdhabalia commented on code in PR #3924:
URL: https://github.com/apache/bookkeeper/pull/3924#discussion_r1170439171
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/bookie/SanityTestCommand.java:
##########
@@ -81,59 +86,126 @@ public boolean apply(ServerConfiguration conf, SanityFlags cmdFlags) {
}
}
- private boolean handle(ServerConfiguration conf, SanityFlags cmdFlags) throws Exception {
+ private static boolean handle(ServerConfiguration conf, SanityFlags cmdFlags) throws Exception {
+ try {
+ return handleAsync(conf, cmdFlags).get();
+ } catch (Exception e) {
+ LOG.warn("Error in bookie sanity test", e);
+ return false;
+ }
+ }
+
+ public static CompletableFuture<Boolean> handleAsync(ServerConfiguration conf, SanityFlags cmdFlags) {
+ CompletableFuture<Boolean> result = new CompletableFuture<Boolean>();
ClientConfiguration clientConf = new ClientConfiguration();
clientConf.addConfiguration(conf);
clientConf.setEnsemblePlacementPolicy(LocalBookieEnsemblePlacementPolicy.class);
clientConf.setAddEntryTimeout(cmdFlags.timeout);
clientConf.setReadEntryTimeout(cmdFlags.timeout);
- BookKeeper bk = new BookKeeper(clientConf);
- LedgerHandle lh = null;
+ BookKeeper bk;
try {
- lh = bk.createLedger(1, 1, BookKeeper.DigestType.MAC, new byte[0]);
- LOG.info("Create ledger {}", lh.getId());
+ bk = new BookKeeper(clientConf);
+ } catch (BKException | IOException | InterruptedException e) {
+ LOG.warn("Failed to initialize bookkeeper client", e);
+ result.completeExceptionally(e);
+ return result;
+ }
+ bk.asyncCreateLedger(1, 1, BookKeeper.DigestType.MAC, new byte[0], (rc, lh, ctx) -> {
+ if (rc != BKException.Code.OK) {
+ LOG.warn("ledger creation failed for sanity command {}", rc);
+ result.completeExceptionally(BKException.create(rc));
+ return;
+ }
+ List<CompletableFuture<Void>> entriesFutures = new ArrayList<>();
for (int i = 0; i < cmdFlags.entries; i++) {
String content = "entry-" + i;
- lh.addEntry(content.getBytes(UTF_8));
- }
-
- LOG.info("Written {} entries in ledger {}", cmdFlags.entries, lh.getId());
-
- // Reopen the ledger and read entries
- lh = bk.openLedger(lh.getId(), BookKeeper.DigestType.MAC, new byte[0]);
- if (lh.getLastAddConfirmed() != (cmdFlags.entries - 1)) {
- throw new Exception("Invalid last entry found on ledger. expecting: " + (cmdFlags.entries - 1)
- + " -- found: " + lh.getLastAddConfirmed());
+ CompletableFuture<Void> entryFuture = new CompletableFuture<>();
+ entriesFutures.add(entryFuture);
+ lh.asyncAddEntry(content.getBytes(UTF_8), (arc, alh, entryId, actx) -> {
+ if (arc != BKException.Code.OK) {
+ LOG.warn("ledger add entry failed for {}-{}", alh.getId(), arc);
+ entryFuture.completeExceptionally(BKException.create(arc));
+ return;
+ }
+ entryFuture.complete(null);
+ }, null);
}
+ CompletableFuture<LedgerHandle> lhFuture = new CompletableFuture<>();
+ CompletableFuture<Void> readEntryFuture = new CompletableFuture<>();
+
+ FutureUtils.collect(entriesFutures).thenCompose(_r -> {
+ bk.asyncOpenLedger(lh.getId(), BookKeeper.DigestType.MAC, new byte[0], (orc, olh, octx) -> {
+ if (orc != BKException.Code.OK) {
+ LOG.warn("open sanity ledger failed for {}-{}", lh.getId(), orc);
+ lhFuture.completeExceptionally(BKException.create(orc));
+ return;
+ }
+ long lac = olh.getLastAddConfirmed();
+ if (lac != (cmdFlags.entries - 1)) {
+ lhFuture.completeExceptionally(new Exception("Invalid last entry found on ledger. expecting: "
+ + (cmdFlags.entries - 1) + " -- found: " + lac));
+ return;
+ }
+ lhFuture.complete(lh);
+ }, null);
Review Comment:
> I'm not sure whether we need a flag to turn on/off the sanity test
sure, we can add the flag and keep it disable by default and user can enable based on the need.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org