Skip to content

Commit

Permalink
fix: fixed blocks consumed, docs, etc
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Peterson <[email protected]>
  • Loading branch information
mattp-swirldslabs committed Nov 21, 2024
1 parent 898c405 commit a9408fb
Show file tree
Hide file tree
Showing 6 changed files with 291 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void send(@NonNull final SubscribeStreamResponseUnparsed subscribeStreamR

if (streamStarted) {
metricsService
.get(BlockNodeMetricTypes.Counter.LiveBlockItemsReceived)
.get(BlockNodeMetricTypes.Counter.LiveBlockItemsConsumed)
.add(blockItems.size());
subscribeStreamResponseObserver.onNext(subscribeStreamResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public interface BlockWriter<V> {
* @return an optional containing the block item written to storage if the block item was a
* block proof signaling the end of the block, an empty optional otherwise.
* @throws IOException when failing to write the block item to storage.
* @throws ParseException when failing to parse a block item.
*/
Optional<V> write(@NonNull final V blockItem) throws IOException, ParseException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@

package com.hedera.block.server.persistence.storage.write;

import static com.hedera.block.server.metrics.BlockNodeMetricTypes.Counter.BlocksPersisted;
import static java.lang.System.Logger.Level.INFO;

import com.hedera.block.server.config.BlockNodeContext;
import com.hedera.block.server.metrics.MetricsService;
import com.hedera.hapi.block.BlockItemUnparsed;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.IOException;
Expand All @@ -34,15 +32,12 @@
*/
public class NoOpBlockWriter implements BlockWriter<List<BlockItemUnparsed>> {

private final MetricsService metricsService;

/**
* Creates a new NoOpBlockWriter instance for testing and troubleshooting only.
*
* @param blockNodeContext the block node context
*/
public NoOpBlockWriter(BlockNodeContext blockNodeContext) {
this.metricsService = blockNodeContext.metricsService();
System.getLogger(getClass().getName()).log(INFO, "Using " + getClass().getSimpleName());
}

Expand All @@ -51,13 +46,11 @@ public NoOpBlockWriter(BlockNodeContext blockNodeContext) {
*/
@Override
public Optional<List<BlockItemUnparsed>> write(@NonNull List<BlockItemUnparsed> blockItems) throws IOException {
try {
if (blockItems.getLast().hasBlockProof()) {
metricsService.get(BlocksPersisted).increment();
}
} catch (Exception e) {
// TODO: what to do here?
System.getLogger(getClass().getName()).log(INFO, "Failed to parse block item: " + e.getMessage());
if (blockItems.getLast().hasBlockProof()) {
// Returning the BlockItems triggers a
// PublishStreamResponse to be sent to the
// upstream producer.
return Optional.of(blockItems);
}

return Optional.empty();
Expand Down
Loading

0 comments on commit a9408fb

Please sign in to comment.