Skip to content

Commit

Permalink
Resolving issues #3 and #2. Committing new and awesome configuration …
Browse files Browse the repository at this point in the history
…mechanism.
  • Loading branch information
bluestreak01 committed Aug 15, 2014
1 parent 78c5198 commit 89e06d6
Show file tree
Hide file tree
Showing 117 changed files with 1,408 additions and 1,862 deletions.
7 changes: 0 additions & 7 deletions nfsdb-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,5 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.nfsdb</groupId>
<artifactId>nfsdb-test-model</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

</dependencies>
</project>
33 changes: 18 additions & 15 deletions nfsdb-core/src/main/java/com/nfsdb/journal/Journal.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import com.nfsdb.journal.exceptions.JournalRuntimeException;
import com.nfsdb.journal.exceptions.JournalUnsupportedTypeException;
import com.nfsdb.journal.factory.JournalClosingListener;
import com.nfsdb.journal.factory.JournalConfiguration;
import com.nfsdb.journal.factory.JournalMetadata;
import com.nfsdb.journal.factory.NullsAdaptor;
import com.nfsdb.journal.factory.configuration.Constants;
import com.nfsdb.journal.factory.configuration.JournalMetadata;
import com.nfsdb.journal.iterators.ConcurrentIterator;
import com.nfsdb.journal.iterators.JournalIterator;
import com.nfsdb.journal.iterators.JournalRowBufferedIterator;
Expand Down Expand Up @@ -258,13 +258,16 @@ public boolean hasIrregularPartition() {
}

public void expireOpenFiles() {
long expiry = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(getMetadata().getOpenPartitionTTL());
for (int i = 0, partitionsSize = partitions.size(); i < partitionsSize; i++) {
Partition<T> partition = partitions.get(i);
if (expiry > partition.getLastAccessed() && partition.isOpen()) {
partition.close();
} else {
partition.expireOpenIndices();
long ttl = getMetadata().getOpenFileTTL();
if (ttl > 0) {
long expiry = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(getMetadata().getOpenFileTTL());
for (int i = 0, partitionsSize = partitions.size(); i < partitionsSize; i++) {
Partition<T> partition = partitions.get(i);
if (expiry > partition.getLastAccessed() && partition.isOpen()) {
partition.close();
} else {
partition.expireOpenIndices();
}
}
}
}
Expand Down Expand Up @@ -369,7 +372,7 @@ public void clearObject(T obj) {
metadata.getNullsAdaptor().clear(obj);
} else {
for (int i = 0, count = metadata.getColumnCount(); i < count; i++) {
JournalMetadata.ColumnMetadata m = metadata.getColumnMetadata(i);
com.nfsdb.journal.factory.configuration.ColumnMetadata m = metadata.getColumnMetadata(i);
switch (m.type) {
case BOOLEAN:
Unsafe.getUnsafe().putBoolean(obj, m.offset, false);
Expand Down Expand Up @@ -539,7 +542,7 @@ public long decrementRowID(long rowID) throws JournalException {
}

public TempPartition<T> createTempPartition(String name) throws JournalException {
int lag = getMetadata().getLagHours();
int lag = getMetadata().getLag();
if (lag <= 0) {
throw new JournalRuntimeException("Journal doesn't support temp partitions: %s", this);
}
Expand Down Expand Up @@ -599,7 +602,7 @@ private void configureColumns() throws JournalException {
columnMetadata = new ColumnMetadata[columnCount];
for (int i = 0; i < columnCount; i++) {
columnMetadata[i] = new ColumnMetadata();
JournalMetadata.ColumnMetadata meta = metadata.getColumnMetadata(i);
com.nfsdb.journal.factory.configuration.ColumnMetadata meta = metadata.getColumnMetadata(i);
if (meta.type == ColumnType.SYMBOL && meta.sameAs == null) {
int tabIndex = symbolTables.size();
int tabSize = tx.symbolTableSizes.length > tabIndex ? tx.symbolTableSizes[tabIndex] : 0;
Expand All @@ -615,7 +618,7 @@ private void configureColumns() throws JournalException {

private void configureSymbolTableSynonyms() {
for (int i = 0, columnCount = getMetadata().getColumnCount(); i < columnCount; i++) {
JournalMetadata.ColumnMetadata meta = metadata.getColumnMetadata(i);
com.nfsdb.journal.factory.configuration.ColumnMetadata meta = metadata.getColumnMetadata(i);
if (meta.type == ColumnType.SYMBOL && meta.sameAs != null) {
SymbolTable tab = getSymbolTable(meta.sameAs);
symbolTableMap.put(meta.name, tab);
Expand All @@ -627,7 +630,7 @@ private void configureSymbolTableSynonyms() {
private void configurePartitions() throws JournalException {
File[] files = getLocation().listFiles(new FileFilter() {
public boolean accept(File f) {
return f.isDirectory() && !f.getName().startsWith(JournalConfiguration.TEMP_DIRECTORY_PREFIX);
return f.isDirectory() && !f.getName().startsWith(Constants.TEMP_DIRECTORY_PREFIX);
}
});

Expand Down Expand Up @@ -738,6 +741,6 @@ void refreshInternal() throws JournalException {

public static class ColumnMetadata {
public SymbolTable symbolTable;
public JournalMetadata.ColumnMetadata meta;
public com.nfsdb.journal.factory.configuration.ColumnMetadata meta;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.nfsdb.journal.concurrent.TimerCache;
import com.nfsdb.journal.exceptions.JournalException;
import com.nfsdb.journal.factory.JournalMetadata;
import com.nfsdb.journal.factory.configuration.JournalMetadata;

public class JournalBulkReader<T> extends Journal<T> {
public JournalBulkReader(JournalMetadata<T> metadata, JournalKey<T> key, TimerCache timerCache) throws JournalException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.nfsdb.journal.concurrent.TimerCache;
import com.nfsdb.journal.exceptions.JournalException;
import com.nfsdb.journal.factory.JournalMetadata;
import com.nfsdb.journal.factory.configuration.JournalMetadata;

public class JournalBulkWriter<T> extends JournalWriter<T> {
public JournalBulkWriter(JournalMetadata<T> metadata, JournalKey<T> key, TimerCache timerCache) throws JournalException {
Expand Down
61 changes: 34 additions & 27 deletions nfsdb-core/src/main/java/com/nfsdb/journal/JournalKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,69 +16,71 @@

package com.nfsdb.journal;

import com.nfsdb.journal.factory.JournalConfiguration;
import com.nfsdb.journal.factory.configuration.Constants;
import com.nfsdb.journal.utils.ByteBuffers;
import com.nfsdb.journal.utils.Files;

import java.nio.ByteBuffer;

public class JournalKey<T> {
private final String clazz;
private final String modelClassName;
private final Class<T> modelClass;
private String location;
private PartitionType partitionType = PartitionType.DEFAULT;
private int recordHint = JournalConfiguration.NULL_RECORD_HINT;
private int recordHint = Constants.NULL_RECORD_HINT;
private boolean ordered = true;

public JournalKey(Class<T> clazz) {
this.clazz = clazz.getName();
this.modelClass = clazz;
this.modelClassName = clazz.getName();
}

public JournalKey(Class<T> clazz, int recordHint) {
this.clazz = clazz.getName();
this.modelClass = clazz;
this.modelClassName = clazz.getName();
this.recordHint = recordHint;
}

public JournalKey(Class<T> clazz, String location) {
this.clazz = clazz.getName();
this.location = location;
}


public JournalKey(String clazz, String location) {
this.clazz = clazz;
this.modelClass = clazz;
this.modelClassName = clazz.getName();
this.location = location;
}

public JournalKey(Class<T> clazz, String location, PartitionType partitionType) {
this.clazz = clazz.getName();
this.modelClass = clazz;
this.modelClassName = clazz.getName();
this.location = location;
this.partitionType = partitionType;
}

public JournalKey(Class<T> clazz, String location, PartitionType partitionType, int recordHint) {
this.clazz = clazz.getName();
this.modelClass = clazz;
this.modelClassName = clazz.getName();
this.location = location;
this.partitionType = partitionType;
this.recordHint = recordHint;
}

public JournalKey(Class<T> clazz, String location, PartitionType partitionType, int recordHint, boolean ordered) {
this.clazz = clazz.getName();
this.modelClass = clazz;
this.modelClassName = clazz.getName();
this.location = location;
this.partitionType = partitionType;
this.recordHint = recordHint;
this.ordered = ordered;
}

public JournalKey(Class<T> clazz, String location, PartitionType partitionType, boolean ordered) {
this.clazz = clazz.getName();
this.modelClass = clazz;
this.modelClassName = clazz.getName();
this.location = location;
this.partitionType = partitionType;
this.ordered = ordered;
}

public static JournalKey<Object> fromBuffer(ByteBuffer buffer) {
// clazz
// modelClassName
int clazzLen = buffer.getInt();
byte[] clazz = new byte[clazzLen];
buffer.get(clazz);
Expand All @@ -101,8 +103,12 @@ public static JournalKey<Object> fromBuffer(ByteBuffer buffer) {
return new JournalKey<>(new String(clazz, Files.UTF_8), location == null ? null : new String(location), partitionType, recordHint, ordered);
}

public String getClazz() {
return clazz;
public String getModelClassName() {
return modelClassName;
}

public Class<T> getModelClass() {
return modelClass;
}

public String getLocation() {
Expand All @@ -126,13 +132,13 @@ public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof JournalKey)) return false;
JournalKey that = (JournalKey) o;
return ordered == that.ordered && recordHint == that.recordHint && !(clazz != null ? !clazz.equals(that.clazz) : that.clazz != null) && !(location != null ? !location.equals(that.location) : that.location != null) && partitionType == that.partitionType;
return ordered == that.ordered && recordHint == that.recordHint && !(modelClassName != null ? !modelClassName.equals(that.modelClassName) : that.modelClassName != null) && !(location != null ? !location.equals(that.location) : that.location != null) && partitionType == that.partitionType;

}

@Override
public int hashCode() {
int result = clazz != null ? clazz.hashCode() : 0;
int result = modelClassName != null ? modelClassName.hashCode() : 0;
result = 31 * result + (location != null ? location.hashCode() : 0);
result = 31 * result + (partitionType != null ? partitionType.hashCode() : 0);
result = 31 * result + recordHint;
Expand All @@ -143,7 +149,7 @@ public int hashCode() {
@Override
public String toString() {
return "JournalKey{" +
"clazz=" + clazz +
"modelClassName=" + modelClassName +
", location='" + location + '\'' +
", partitionType=" + partitionType +
", recordHint=" + recordHint +
Expand All @@ -154,13 +160,13 @@ public String toString() {
//////////////////////// REPLICATION CODE //////////////////////

public int getBufferSize() {
return 4 + clazz.getBytes(Files.UTF_8).length + 4 + 2 * (location == null ? 0 : location.length()) + 1 + 1 + 4;
return 4 + modelClassName.getBytes(Files.UTF_8).length + 4 + 2 * (location == null ? 0 : location.length()) + 1 + 1 + 4;
}

public void write(ByteBuffer buffer) {
// clazz
buffer.putInt(clazz.length());
for (byte b : clazz.getBytes(Files.UTF_8)) {
// modelClassName
buffer.putInt(modelClassName.length());
for (byte b : modelClassName.getBytes(Files.UTF_8)) {
buffer.put(b);
}
// location
Expand All @@ -174,7 +180,8 @@ public void write(ByteBuffer buffer) {
}

private JournalKey(String clazz, String location, PartitionType partitionType, int recordHint, boolean ordered) {
this.clazz = clazz;
this.modelClass = null;
this.modelClassName = clazz;
this.location = location;
this.partitionType = partitionType;
this.recordHint = recordHint;
Expand Down

0 comments on commit 89e06d6

Please sign in to comment.