Skip to content

Commit

Permalink
Merge pull request #6223 from zeusoo001/log-opt-1
Browse files Browse the repository at this point in the history
feat(event): optimize event service log
  • Loading branch information
CodeNinjaEvan authored Mar 4, 2025
2 parents f9a4544 + a75e41d commit 9a70395
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public static void init(BlockCapsule.BlockId blockId) {
}

public static void add(BlockEvent blockEvent) throws EventException {
logger.info("Add block event, {}, {}", blockEvent.getBlockId().getString(),
blockEvent.getParentId().getString());
logger.info("Add block event, {}, {}, {}", blockEvent.getBlockId().getString(),
blockEvent.getParentId().getString(), blockEvent.getSolidId().getString());
if (blockEventMap.get(blockEvent.getParentId()) == null) {
throw new EventException("unlink BlockEvent, "
+ blockEvent.getBlockId().getString() + ", "
Expand Down Expand Up @@ -83,6 +83,7 @@ public static void remove(BlockCapsule.BlockId solidId) {
}

public static List<BlockEvent> getSolidBlockEvents(BlockCapsule.BlockId solidId) {
logger.info("Get solid events {}, {}", solidNum, solidId);
List<BlockEvent> blockEvents = new ArrayList<>();
BlockCapsule.BlockId tmp = solidId;
while (tmp.getNum() > solidNum) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ public void work() {
return;
}

List<BlockEvent> blockEvents = BlockEventCache.getSolidBlockEvents(solidId);
List<BlockEvent> blockEvents;

try {
blockEvents = BlockEventCache.getSolidBlockEvents(solidId);
} catch (Exception e) {
logger.warn("Get solid events failed. {}", e.getMessage());
return;
}

blockEvents.forEach(v -> flush(v));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public void test() throws Exception {
BlockCapsule.BlockId b1 = new BlockCapsule.BlockId(getBlockId(), 1);
be1.setBlockId(b1);
be1.setParentId(b1);
be1.setSolidId(b1);
try {
BlockEventCache.add(be1);
Assert.fail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ public class SolidEventServiceTest {

@Test
public void test() throws Exception {
BlockEvent be0 = new BlockEvent();
BlockCapsule.BlockId b0 = new BlockCapsule.BlockId(BlockEventCacheTest.getBlockId(), 1);
be0.setBlockId(b0);
be0.setParentId(b0);
be0.setSolidId(new BlockCapsule.BlockId(BlockEventCacheTest.getBlockId(), 100));
BlockEventCache.init(b0);
BlockEventCache.add(be0);
solidEventService.work();

BlockEvent be1 = new BlockEvent();
BlockCapsule.BlockId b1 = new BlockCapsule.BlockId(BlockEventCacheTest.getBlockId(), 1);
be1.setBlockId(b1);
Expand Down

0 comments on commit 9a70395

Please sign in to comment.