Skip to content

Commit

Permalink
Fix potential race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
burmanm committed Jun 28, 2017
1 parent 6b37038 commit e80a48b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ private void next() {
storedTimestamp = blockTimestamp + storedDelta;
} else {
nextTimestamp();
nextValue();
}
}

Expand Down Expand Up @@ -106,6 +105,7 @@ private void nextTimestamp() {

storedDelta = storedDelta + deltaDelta;
storedTimestamp = storedDelta + storedTimestamp;
nextValue();
}

private void nextValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ private void next() {
}

nextTimestamp();
nextValue();
}

private void first() {
Expand All @@ -73,6 +72,7 @@ private void nextTimestamp() {
switch(readInstruction) {
case 0x00:
storedTimestamp = storedDelta + storedTimestamp;
nextValue();
return;
case 0x02:
deltaDelta = in.getLong(7);
Expand Down Expand Up @@ -101,6 +101,7 @@ private void nextTimestamp() {
storedDelta = storedDelta + deltaDelta;

storedTimestamp = storedDelta + storedTimestamp;
nextValue();
}

private void nextValue() {
Expand Down
32 changes: 0 additions & 32 deletions src/test/java/fi/iki/yak/ts/compression/gorilla/EncodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ void testEmptyBlock() throws Exception {
assertNull(d.readPair());
}

/**
* Long values should be compressable and decompressable in the stream
*/
@Test
void testLongEncoding() throws Exception {
// This test should trigger ByteBuffer reallocation
Expand Down Expand Up @@ -228,33 +225,4 @@ void testLongEncoding() throws Exception {
}
assertNull(d.readPair());
}

@Test
void testIssue11() {
long now = System.currentTimeMillis();
LongArrayOutput output = new LongArrayOutput(500);
GorillaCompressor c = new GorillaCompressor(LocalDateTime.now(ZoneOffset.UTC).truncatedTo(ChronoUnit.HOURS).
toInstant(ZoneOffset.UTC).toEpochMilli(), output);

Map<Long, Double> dps = new TreeMap<>();
int n = 3600;
Random r = new Random();
for(int i=0; i<n; i++) {
dps.put(now + (1000 * i) + r.nextInt(100), 100.0);
}

for(Map.Entry<Long, Double> entry : dps.entrySet()) {
c.addValue(entry.getKey(), entry.getValue());
}
c.close();

LongArrayInput input = new LongArrayInput(output.getLongArray());
GorillaDecompressor dc = new GorillaDecompressor(input);

Pair pair = dc.readPair();
while(pair != null) {
assertTrue(dps.containsKey(pair.getTimestamp()), "Datapoint was missing");
pair = dc.readPair();
}
}
}

0 comments on commit e80a48b

Please sign in to comment.