Skip to content

Commit 7f338db

Browse files
committed
Merge branch '7.3' of github.com:gchq/stroom into 7.3
2 parents 203e11e + 44ad3b1 commit 7f338db

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ DO NOT ADD CHANGES HERE - ADD THEM USING log_change.sh
1313
~~~
1414

1515

16+
## [v7.3-beta.18] - 2024-04-16
17+
18+
* Issue **#4215** : Fix NPE during context lookup with no context data loaded.
19+
20+
1621
## [v7.3-beta.17] - 2024-04-16
1722

1823
* Issue **#4214** : Fix index shard writer errors.
@@ -437,7 +442,8 @@ eval EventId = first(EventId)`, `evt` => `eval EventId = first(EventId)` and `st
437442
* Issue **#3830** : Add S3 data storage option.
438443

439444

440-
[Unreleased]: https://github.com/gchq/stroom/compare/v7.3-beta.17...HEAD
445+
[Unreleased]: https://github.com/gchq/stroom/compare/v7.3-beta.18...HEAD
446+
[v7.3-beta.18]: https://github.com/gchq/stroom/compare/v7.3-beta.17...v7.3-beta.18
441447
[v7.3-beta.17]: https://github.com/gchq/stroom/compare/v7.3-beta.16...v7.3-beta.17
442448
[v7.3-beta.16]: https://github.com/gchq/stroom/compare/v7.3-beta.15...v7.3-beta.16
443449
[v7.3-beta.15]: https://github.com/gchq/stroom/compare/v7.3-beta.14...v7.3-beta.15

stroom-pipeline/src/main/java/stroom/pipeline/refdata/ReferenceData.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ private void loadContextData(
422422
final long byteCount = contextStream.size();
423423
// Only use context data if we actually have some.
424424
if (byteCount > MINIMUM_BYTE_COUNT) {
425-
// load the context data into the RefDataStore so it is available for lookups
425+
// load the context data into the RefDataStore, so it is available for lookups
426426
contextDataLoader.load(
427427
contextStream,
428428
meta,

stroom-pipeline/src/main/java/stroom/pipeline/refdata/store/onheapstore/RefDataOnHeapStore.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import stroom.pipeline.refdata.store.RefStoreEntry;
1212
import stroom.pipeline.refdata.store.RefStreamDefinition;
1313
import stroom.pipeline.refdata.store.offheapstore.TypedByteBuffer;
14+
import stroom.util.NullSafe;
1415
import stroom.util.logging.LambdaLogger;
1516
import stroom.util.logging.LambdaLoggerFactory;
1617
import stroom.util.logging.LogUtil;
@@ -107,17 +108,23 @@ public Optional<RefDataValue> getValue(final MapDefinition mapDefinition, final
107108
// just do the range lookup
108109
final long keyLong = Long.parseLong(key);
109110

110-
// look up our long key in the range store to see if it is part of a range
111-
NavigableMap<Range<Long>, RefDataValue> rangeSubMap = rangeValueNestedMap.get(mapDefinition);
112-
result = getValueByRange(rangeSubMap, keyLong);
111+
// Look up our long key in the range store to see if it is part of a range.
112+
// It is possible for an event stream to have no associated context stream, or
113+
// the context stream may not contain the map and/or key requested in the lookup
114+
final NavigableMap<Range<Long>, RefDataValue> rangeSubMap = rangeValueNestedMap.get(mapDefinition);
115+
if (NullSafe.hasEntries(rangeSubMap)) {
116+
result = getValueByRange(rangeSubMap, keyLong);
117+
} else {
118+
result = Optional.empty();
119+
}
113120

114121
} catch (NumberFormatException e) {
115122
// key could not be converted to a long, either this mapdef has no ranges or
116123
// an invalid key was used. See if we have any ranges at all for this mapdef
117124
// to determine whether to error or not.
118125
boolean doesStoreContainRanges = rangeValueNestedMap.containsKey(mapDefinition);
119126
if (doesStoreContainRanges) {
120-
// we have ranges for this map def so we would expect to be able to convert the key
127+
// we have ranges for this map def, so we would expect to be able to convert the key
121128
throw new RuntimeException(LogUtil.message(
122129
"Key {} cannot be used with the range store as it cannot be converted to a long",
123130
key),
@@ -169,9 +176,7 @@ private Optional<RefDataValue> getValueByRange(final NavigableMap<Range<Long>, R
169176

170177
// create a sub-set of the map starting at the key of interest or the next smallest
171178
// range from value. Note the map is reverse sorted to increase confusion.
172-
173179
final SortedMap<Range<Long>, RefDataValue> tailMap = rangeSubMap.tailMap(startKey);
174-
175180
for (Map.Entry<Range<Long>, RefDataValue> entry : tailMap.entrySet()) {
176181
// see if our key is in the found range
177182
if (entry.getKey().contains(key)) {
@@ -209,7 +214,7 @@ public List<RefStoreEntry> list(final int limit,
209214
throw new UnsupportedOperationException("Not yet implemented");
210215
}
211216

212-
// @Override
217+
// @Override
213218
// public <T> T consumeEntryStream(final Function<Stream<RefStoreEntry>, T> streamFunction) {
214219
// throw new UnsupportedOperationException("Not yet implemented");
215220
// }

stroom-pipeline/src/test/java/stroom/pipeline/refdata/store/onheapstore/TestRefDataOnHeapStore.java

+26
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,32 @@ void testOverwrite_doNotOverwrite_rangeValueStore() {
228228
doKeyRangeValueOverwriteTest(false, value1, value2, expectedFinalValue);
229229
}
230230

231+
@Test
232+
void testGetWithNoLoad_stringKey() {
233+
final RefStreamDefinition refStreamDefinition = buildUniqueRefStreamDefinition();
234+
MapDefinition mapDefinition = new MapDefinition(refStreamDefinition, "map1");
235+
String key = "myKey";
236+
237+
assertThat(refDataStore.getKeyValueEntryCount())
238+
.isEqualTo(0);
239+
240+
assertThat(refDataStore.getValue(mapDefinition, key))
241+
.isEmpty();
242+
}
243+
244+
@Test
245+
void testGetWithNoLoad_longKey() {
246+
final RefStreamDefinition refStreamDefinition = buildUniqueRefStreamDefinition();
247+
MapDefinition mapDefinition = new MapDefinition(refStreamDefinition, "map1");
248+
String key = "123";
249+
250+
assertThat(refDataStore.getKeyValueEntryCount())
251+
.isEqualTo(0);
252+
253+
assertThat(refDataStore.getValue(mapDefinition, key))
254+
.isEmpty();
255+
}
256+
231257
private void doKeyValueOverwriteTest(final boolean overwriteExisting,
232258
final StringValue value1,
233259
final StringValue value2,

0 commit comments

Comments
 (0)