Skip to content

Commit

Permalink
#4682 PlanB State Store
Browse files Browse the repository at this point in the history
  • Loading branch information
stroomdev66 committed Jan 28, 2025
1 parent 62b0ce0 commit bf3726a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,38 @@ public ShardWriter(final PlanBDocCache planBDocCache,
}

public Optional<PlanBDoc> getDoc(final String mapName, final Consumer<String> errorConsumer) {
if (NullSafe.isBlankString(mapName)) {
errorConsumer.accept("Null map name");
return Optional.empty();
}
Optional<PlanBDoc> result = Optional.empty();

try {
if (NullSafe.isBlankString(mapName)) {
throw new RuntimeException("Null map name");
}

return stateDocMap.computeIfAbsent(mapName, k -> {
PlanBDoc doc = null;
result = stateDocMap.computeIfAbsent(mapName, k -> {
PlanBDoc doc = null;

if (!PlanBNameValidator.isValidName(k)) {
errorConsumer.accept("Bad map name: " + k);
} else {
try {
doc = planBDocCache.get(k);
if (doc == null) {
errorConsumer.accept("Unable to find state doc for map name: " + k);
if (!PlanBNameValidator.isValidName(k)) {
throw new RuntimeException("Bad map name: " + k);
} else {
doc = planBDocCache.get(k);
if (doc == null) {
throw new RuntimeException("Unable to find state doc for map name: " + k);
}
}
} catch (final RuntimeException e) {
LOGGER.debug(e::getMessage, e);
errorConsumer.accept(e.getMessage());
}
}

return Optional.ofNullable(doc);
});
return Optional.ofNullable(doc);
});
} catch (final RuntimeException e) {
LOGGER.debug(e::getMessage, e);
errorConsumer.accept(e.getMessage());
}

return result;
}

private static class WriterInstance implements AutoCloseable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ private String getPrefix(final String qName) {
*/
@Override
public void endElement(final String uri, final String localName, final String qName) throws SAXException {
LOGGER.trace("endElement {} {} {} level:{}", uri, localName, qName, depthLevel);
LOGGER.trace("endElement {} {} {} level:{} content:{}", uri, localName, qName, depthLevel, contentBuffer);

insideElement = false;
if (VALUE_ELEMENT.equalsIgnoreCase(localName)) {
Expand Down Expand Up @@ -509,26 +509,17 @@ private void handleValueEndElement() throws SAXException {
}

private void addData() {
LOGGER.debug(() -> "Adding data to map: " + mapName);
final Optional<PlanBDoc> optional = writer.getDoc(mapName, this::error);
optional.ifPresent(doc -> {
// End of the data item so ensure it is persisted in the store
try {
switch (doc.getStateType()) {
case STATE -> {
addState(doc);
}
case TEMPORAL_STATE -> {
addTemporalState(doc);
}
case RANGED_STATE -> {
addRangedState(doc);
}
case TEMPORAL_RANGED_STATE -> {
addTemporalRangedState(doc);
}
case SESSION -> {
addSession(doc);
}
case STATE -> addState(doc);
case TEMPORAL_STATE -> addTemporalState(doc);
case RANGED_STATE -> addRangedState(doc);
case TEMPORAL_RANGED_STATE -> addTemporalRangedState(doc);
case SESSION -> addSession(doc);
default -> error("Unexpected state type: " + doc.getStateType());
}
} catch (final BufferOverflowException boe) {
Expand Down
24 changes: 24 additions & 0 deletions unreleased_changes/20250128_164727_119__4682.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
* Issue **#4682** : Improve Plan B filter error handling.


```sh
# ********************************************************************************
# Issue title: PlanB State Store
# Issue link: https://github.com/gchq/stroom/issues/4682
# ********************************************************************************

# ONLY the top line will be included as a change entry in the CHANGELOG.
# The entry should be in GitHub flavour markdown and should be written on a SINGLE
# line with no hard breaks. You can have multiple change files for a single GitHub issue.
# The entry should be written in the imperative mood, i.e. 'Fix nasty bug' rather than
# 'Fixed nasty bug'.
#
# Examples of acceptable entries are:
#
#
# * Issue **123** : Fix bug with an associated GitHub issue in this repository
#
# * Issue **namespace/other-repo#456** : Fix bug with an associated GitHub issue in another repository
#
# * Fix bug with no associated GitHub issue.
```

0 comments on commit bf3726a

Please sign in to comment.