Skip to content

Commit

Permalink
1.8.1-SNAPSHOT and detect concurrent writes.
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-lawrey committed Sep 19, 2013
1 parent 76e050e commit a889f33
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 43 deletions.
3 changes: 2 additions & 1 deletion chronicle-fix/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
<parent>
<artifactId>chronicle-parent</artifactId>
<groupId>com.higherfrequencytrading</groupId>
<version>1.8-SNAPSHOT</version>
<version>1.8.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion chronicle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<groupId>com.higherfrequencytrading</groupId>
<artifactId>chronicle</artifactId>
<version>1.8</version>
<version>1.8.1-SNAPSHOT</version>
<name>Java-Chronicle</name>
<description>High Performance Logging and Persisted Messaging</description>
<packaging>bundle</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
public abstract class AbstractChronicle implements DirectChronicle {
private final String name;
private final Map<Class, EnumeratedMarshaller> marshallerMap = new LinkedHashMap<Class, EnumeratedMarshaller>();
protected long size = 0;
// shouldn't need to be volatile, unless you have a bug in the calling code ;)
protected volatile long size = 0;
private boolean multiThreaded = false;

protected AbstractChronicle(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public void startExcerpt(int capacity) {
long endPosition = startPosition + capacity;
index0(chronicle.size(), startPosition, endPosition);
forWrite = true;
index = chronicle.size();
}

@Override
Expand Down Expand Up @@ -486,7 +487,7 @@ private void readUTF1(@NotNull Appendable appendable, @NotNull StopCharTester te
break;
}
default:
/* 10xx xxxx, 1111 xxxx */
/* 10xx xxxx, 1111 xxxx */
throw new UTFDataFormatException(
"malformed input around byte ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.List;
import java.util.logging.Logger;

Expand Down Expand Up @@ -112,6 +113,19 @@ public IndexedChronicle(String basePath, int dataBitSizeHint, ByteOrder byteOrde
}
}

private static String extractName(String basePath) {
File file = new File(basePath);
String name = file.getName();
if (name != null && name.length() > 0)
return name;
file = file.getParentFile();
if (file == null) return "chronicle";
name = file.getName();
if (name != null && name.length() > 0)
return name;
return "chronicle";
}

@Override
public long getIndexData(long indexId) {
long indexOffset = indexId << indexBitSize();
Expand Down Expand Up @@ -178,19 +192,6 @@ protected int indexBitSize() {
return 3;
}

private static String extractName(String basePath) {
File file = new File(basePath);
String name = file.getName();
if (name != null && name.length() > 0)
return name;
file = file.getParentFile();
if (file == null) return "chronicle";
name = file.getName();
if (name != null && name.length() > 0)
return name;
return "chronicle";
}

@Override
public long sizeInBytes() {
try {
Expand Down Expand Up @@ -273,7 +274,7 @@ public int positionInBuffer(long startPosition) {
public long startExcerpt(int capacity) {
final long size = this.size;
long startPosition = getIndexData(size);
assert size == 0 || startPosition != 0;
assert size == 0 || startPosition != 0 : "size: " + size + " startPosition: " + startPosition + " is the chronicle corrupted?";
// does it overlap a ByteBuffer barrier.
if ((startPosition & ~dataLowMask) != ((startPosition + capacity) & ~dataLowMask)) {
// resize the previous entry.
Expand All @@ -285,8 +286,11 @@ public long startExcerpt(int capacity) {

@Override
public void incrementSize(long expected) {
if (size + 1 != expected)
throw new ConcurrentModificationException("size: " + (size + 1) + ", expected: " + expected + ", Have you updated the chronicle without thread safety?");
assert size == 0 || getIndexData(size) > 0 : "Failed to set the index at " + size + " was 0.";

size++;
assert size == expected : "size: " + size + ", expected: " + expected;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
<parent>
<groupId>com.higherfrequencytrading</groupId>
<artifactId>chronicle-parent</artifactId>
<version>1.8-SNAPSHOT</version>
<version>1.8.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<groupId>com.higherfrequencytrading</groupId>
<artifactId>chronicle-demo</artifactId>

<name>chronicle-demo</name>
<version>1.8-SNAPSHOT</version>
<version>1.8.1-SNAPSHOT</version>
<description>Demo Processing Engine</description>
<dependencies>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion demo2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<artifactId>chronicle-demo2</artifactId>

<name>Chronicle Demo with three nodes</name>
<version>1.8-SNAPSHOT</version>
<version>1.8.1-SNAPSHOT</version>
<description>Demo Processing Engine</description>
<dependencies>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion hiccup/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<dependency>
<groupId>com.higherfrequencytrading</groupId>
<artifactId>chronicle</artifactId>
<version>1.7.3-SNAPSHOT</version>
<version>1.8.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
19 changes: 1 addition & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<groupId>com.higherfrequencytrading</groupId>
<artifactId>chronicle-parent</artifactId>
<version>1.8-SNAPSHOT</version>
<version>1.8.1-SNAPSHOT</version>
<packaging>pom</packaging>

<name>chronicle-parent</name>
Expand Down Expand Up @@ -115,23 +115,6 @@
<nohelp>true</nohelp>
</configuration>
</plugin>
<!-- plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.4</version>
<configuration>
<passphrase>${gpg.passphrase}</passphrase>
</configuration>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin -->
</plugins>
</build>

Expand Down
5 changes: 3 additions & 2 deletions testing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
<parent>
<groupId>com.higherfrequencytrading</groupId>
<artifactId>chronicle-parent</artifactId>
<version>1.8-SNAPSHOT</version>
<version>1.8.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<groupId>com.higherfrequencytrading</groupId>
<artifactId>chronicle-testing</artifactId>
<version>1.8-SNAPSHOT</version>
<version>1.8.1-SNAPSHOT</version>

<dependencies>
<dependency>
Expand Down

0 comments on commit a889f33

Please sign in to comment.