Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Recreate li 907 branch.

  • Loading branch information...
commit 08da446f53f9a1f98a094d7a35556859236fc438 2 parents 766a896 + 799800f
@jkreps jkreps authored
View
27 build.xml
@@ -27,23 +27,7 @@
</sequential>
</macrodef>
- <target name="all" depends="clean, jar, war, test" description="Build all artifacts." />
-
- <target name="usage">
- <echo message=""/>
- <echo message="${name} build file"/>
- <echo message="-----------------------------------"/>
- <echo message=""/>
- <echo message="Available targets are:"/>
- <echo message=""/>
- <echo message="build -- Build the application"/>
- <echo message="client -- Build a jar file for clients to use"/>
- <echo message="jar -- Build a jar file for the client."/>
- <echo message="war -- Build a war file for deploying the server to a servlet container"/>
- <echo message="docs -- Create html documentation"/>
- <echo message="clean -- Delete generated files"/>
- <echo message=""/>
- </target>
+ <target name="all" depends="clean, srcjar, jar, war, test" description="Build all artifacts." />
<target name="clean" description="Delete generated files.">
<delete dir="${dist.dir}" />
@@ -83,6 +67,15 @@
</fileset>
</jar>
</target>
+
+ <target name="srcjar" description="Build source jar file">
+ <mkdir dir="${dist.dir}"/>
+ <jar destfile="${dist.dir}/${name}-${curr.release}-src.jar">
+ <fileset dir="${java.dir}">
+ <include name="**/*.java"/>
+ </fileset>
+ </jar>
+ </target>
<target name="utils" depends="build" description="Build a jar file with voldemort util classes.">
<tstamp>
View
20 src/java/voldemort/serialization/json/JsonTypeSerializer.java
@@ -203,8 +203,7 @@ private Object read(DataInputStream stream, Object type) throws IOException {
}
}
- private void writeBoolean(DataOutputStream output, Boolean o) throws IOException {
- Boolean b = (Boolean) o;
+ private void writeBoolean(DataOutputStream output, Boolean b) throws IOException {
if(b == null)
output.writeByte(-1);
else if(b.booleanValue())
@@ -329,8 +328,7 @@ private Byte readInt8(DataInputStream stream) throws IOException {
return b;
}
- private void writeInt8(DataOutputStream output, Byte o) throws IOException {
- Byte b = (Byte) o;
+ private void writeInt8(DataOutputStream output, Byte b) throws IOException {
if(b == null)
output.writeByte(Byte.MIN_VALUE);
else if(b.byteValue() == Byte.MIN_VALUE)
@@ -349,8 +347,7 @@ private Short readInt16(DataInputStream stream) throws IOException {
return s;
}
- private void writeInt16(DataOutputStream output, Short o) throws IOException {
- Short s = (Short) o;
+ private void writeInt16(DataOutputStream output, Short s) throws IOException {
if(s == null)
output.writeShort(Short.MIN_VALUE);
else if(s.shortValue() == Short.MIN_VALUE)
@@ -369,8 +366,7 @@ private Integer readInt32(DataInputStream stream) throws IOException {
return i;
}
- private void writeInt32(DataOutputStream output, Integer o) throws IOException {
- Integer i = (Integer) o;
+ private void writeInt32(DataOutputStream output, Integer i) throws IOException {
if(i == null)
output.writeInt(Integer.MIN_VALUE);
else if(i.intValue() == Integer.MIN_VALUE)
@@ -389,8 +385,7 @@ private Long readInt64(DataInputStream stream) throws IOException {
return l;
}
- private void writeInt64(DataOutputStream output, Long o) throws IOException {
- Long l = (Long) o;
+ private void writeInt64(DataOutputStream output, Long l) throws IOException {
if(l == null)
output.writeLong(Long.MIN_VALUE);
else if(l.longValue() == Long.MIN_VALUE)
@@ -409,8 +404,7 @@ private Float readFloat32(DataInputStream stream) throws IOException {
return f;
}
- private void writeFloat32(DataOutputStream output, Float o) throws IOException {
- Float f = (Float) o;
+ private void writeFloat32(DataOutputStream output, Float f) throws IOException {
if(f == null)
output.writeFloat(Float.MIN_VALUE);
else if(f.floatValue() == Float.MIN_VALUE)
@@ -470,7 +464,7 @@ else if(d.getTime() == Long.MIN_VALUE)
}
private byte[] readBytes(DataInputStream stream) throws IOException {
- int size = (int) stream.readShort();
+ int size = stream.readShort();
if(size < 0)
return null;
byte[] bytes = new byte[size];
View
3  src/java/voldemort/server/storage/StorageService.java
@@ -136,6 +136,7 @@ protected void startInner() {
Cluster cluster = this.metadataStore.getCluster();
List<StoreDefinition> storeDefs = this.metadataStore.getStores();
logger.info("Initializing stores:");
+ Time time = new SystemTime();
for(StoreDefinition def: storeDefs) {
if(!def.getName().equals(MetadataStore.METADATA_STORE_NAME)) {
logger.info("Opening " + def.getName() + ".");
@@ -157,7 +158,7 @@ protected void startInner() {
routingStrategy);
}
if(voldemortConfig.isVerboseLoggingEnabled())
- store = new LoggingStore<byte[], byte[]>(store);
+ store = new LoggingStore<byte[], byte[]>(store, cluster.getName(), time);
if(voldemortConfig.isStatTrackingEnabled())
store = new StatTrackingStore<byte[], byte[]>(store);
this.localStoreMap.put(def.getName(), store);
View
2  src/java/voldemort/store/StorageEngineType.java
@@ -72,4 +72,4 @@ public static StorageEngineType fromDisplay(String type) {
public String toDisplay() {
return text;
}
-};
+}
View
15 src/java/voldemort/store/bdb/BdbStorageEngine.java
@@ -66,7 +66,8 @@
public BdbStorageEngine(String name, Environment environment, Database database) {
assertNotNull("The store name cannot be null.", name);
- assertNotNull("The database cannot be null.", name);
+ assertNotNull("The database cannot be null.", database);
+ assertNotNull("The environment cannot be null.", environment);
this.name = name;
this.bdbDatabase = database;
this.environment = environment;
@@ -246,12 +247,11 @@ public int hashCode() {
return name.hashCode();
}
- @SuppressWarnings("unchecked")
public boolean equals(Object o) {
- if(o == null || !Store.class.equals(o.getClass()))
+ if(o == null || !Store.class.isAssignableFrom(o.getClass()))
return false;
- Store s = (Store) o;
- return s.getName().equals(o);
+ Store<?, ?> s = (Store<?, ?>) o;
+ return s.getName().equals(s.getName());
}
public void close() throws PersistenceFailureException {
@@ -280,7 +280,8 @@ private void attemptCommit(Transaction transaction) {
}
}
- private class BdbStoreIterator implements ClosableIterator<Entry<byte[], Versioned<byte[]>>> {
+ private static class BdbStoreIterator implements
+ ClosableIterator<Entry<byte[], Versioned<byte[]>>> {
private volatile boolean isOpen;
private final Cursor cursor;
@@ -350,7 +351,7 @@ public void close() {
}
@Override
- public void finalize() {
+ protected void finalize() {
if(isOpen) {
logger.error("Failure to close cursor, will be forcably closed.");
close();
View
5 src/java/voldemort/store/gzip/GzipStore.java
@@ -27,7 +27,6 @@
import voldemort.VoldemortException;
import voldemort.store.DelegatingStore;
import voldemort.store.Store;
-import voldemort.versioning.VectorClock;
import voldemort.versioning.Versioned;
/**
@@ -48,7 +47,7 @@ public GzipStore(Store<K, byte[]> innerStore) {
try {
for(Versioned<byte[]> item: found)
results.add(new Versioned<byte[]>(IOUtils.toByteArray(new GZIPInputStream(new ByteArrayInputStream(item.getValue()))),
- (VectorClock) item.getVersion()));
+ item.getVersion()));
} catch(IOException e) {
throw new VoldemortException(e);
}
@@ -60,7 +59,7 @@ public void put(K key, Versioned<byte[]> value) throws VoldemortException {
try {
getInnerStore().put(key,
new Versioned<byte[]>(IOUtils.toByteArray(new GZIPInputStream(new ByteArrayInputStream(value.getValue()))),
- (VectorClock) value.getVersion()));
+ value.getVersion()));
} catch(IOException e) {
throw new VoldemortException(e);
}
View
57 src/java/voldemort/store/logging/LoggingStore.java
@@ -38,18 +38,39 @@
private final Logger logger;
private final Time time;
- private final String storeType;
+ private final String instanceName;
+ /**
+ * Create a logging store that wraps the given store
+ *
+ * @param store The store to wrap
+ */
public LoggingStore(Store<K, V> store) {
this(store, new SystemTime());
}
+ /**
+ * Create a logging store that wraps the given store
+ *
+ * @param store The store to wrap
+ * @param time The time implementation to use for computing ellapsed time
+ */
public LoggingStore(Store<K, V> store, Time time) {
+ this(store, null, time);
+ }
+
+ /**
+ * Create a logging store that wraps the given store
+ *
+ * @param store The store to wrap
+ * @param instance The instance name to display in logging messages
+ * @param time The time implementation to use for computing ellapsed time
+ */
+ public LoggingStore(Store<K, V> store, String instance, Time time) {
super(store);
this.logger = Logger.getLogger(store.getClass());
this.time = time;
- String name = store.getClass().getName();
- this.storeType = name.substring(Math.max(0, name.lastIndexOf('.')), name.length());
+ this.instanceName = instance == null ? ": " : instance + ": ";
}
@Override
@@ -70,12 +91,7 @@ public boolean delete(K key, Version version) throws VoldemortException {
succeeded = true;
return deletedSomething;
} finally {
- if(logger.isDebugEnabled()) {
- double elapsedMs = (time.getNanoseconds() - startTimeNs) / (double) Time.NS_PER_MS;
- logger.debug("DELETE from store '" + getName() + "' completed "
- + (succeeded ? "successfully" : "unsuccessfully") + " in " + elapsedMs
- + " ms.");
- }
+ printTimedMessage("DELETE", succeeded, startTimeNs);
}
}
@@ -90,12 +106,7 @@ public boolean delete(K key, Version version) throws VoldemortException {
succeeded = true;
return l;
} finally {
- if(logger.isDebugEnabled()) {
- double elapsedMs = (time.getNanoseconds() - startTimeNs) / (double) Time.NS_PER_MS;
- logger.debug("GET from store '" + getName() + "' completed "
- + (succeeded ? "successfully" : "unsuccessfully") + " in " + elapsedMs
- + " ms.");
- }
+ printTimedMessage("GET", succeeded, startTimeNs);
}
}
@@ -110,12 +121,16 @@ public void put(K key, Versioned<V> value) throws VoldemortException {
getInnerStore().put(key, value);
succeeded = true;
} finally {
- if(logger.isDebugEnabled()) {
- double elapsedMs = (time.getNanoseconds() - startTimeNs) / (double) Time.NS_PER_MS;
- logger.debug("PUT from store '" + getName() + "' completed "
- + (succeeded ? "successfully" : "unsuccessfully") + " in " + elapsedMs
- + " ms.");
- }
+ printTimedMessage("PUT", succeeded, startTimeNs);
+ }
+ }
+
+ private void printTimedMessage(String operation, boolean success, long startNs) {
+ if(logger.isDebugEnabled()) {
+ double elapsedMs = (time.getNanoseconds() - startNs) / (double) Time.NS_PER_MS;
+ logger.debug(instanceName + operation + " operation on store '" + getName()
+ + "' completed " + (success ? "successfully" : "unsuccessfully") + " in "
+ + elapsedMs + " ms.");
}
}
View
5 src/java/voldemort/store/serialized/SerializingStore.java
@@ -23,7 +23,6 @@
import voldemort.serialization.Serializer;
import voldemort.store.Store;
import voldemort.utils.Utils;
-import voldemort.versioning.VectorClock;
import voldemort.versioning.Version;
import voldemort.versioning.Versioned;
@@ -58,7 +57,7 @@ public boolean delete(K key, Version version) throws VoldemortException {
List<Versioned<V>> results = new ArrayList<Versioned<V>>(found.size());
for(Versioned<byte[]> versioned: found)
results.add(new Versioned<V>(valueSerializer.toObject(versioned.getValue()),
- (VectorClock) versioned.getVersion()));
+ versioned.getVersion()));
return results;
}
@@ -69,7 +68,7 @@ public String getName() {
public void put(K key, Versioned<V> value) throws VoldemortException {
store.put(keySerializer.toBytes(key),
new Versioned<byte[]>(valueSerializer.toBytes(value.getValue()),
- (VectorClock) value.getVersion()));
+ value.getVersion()));
}
public void close() {
View
2  src/java/voldemort/store/slop/Slop.java
@@ -48,7 +48,7 @@ private Operation(byte opCode) {
public byte getOpCode() {
return opCode;
}
- };
+ }
final private byte[] key;
final private byte[] value;
View
2  src/java/voldemort/store/slop/SloppyStore.java
@@ -30,8 +30,6 @@
import voldemort.versioning.Version;
import voldemort.versioning.Versioned;
-;
-
/**
* A Sloppy store is a store wrapper that delegates to an inner store, and if
* that store fails, instead stores some slop in the first of a list of backup
View
6 src/java/voldemort/store/socket/SocketStore.java
@@ -64,7 +64,7 @@ public void close() throws VoldemortException {
public boolean delete(byte[] key, Version version) throws VoldemortException {
StoreUtils.assertValidKey(key);
- SocketAndStreams sands = (SocketAndStreams) pool.checkout(destination);
+ SocketAndStreams sands = pool.checkout(destination);
try {
DataOutputStream outputStream = sands.getOutputStream();
outputStream.writeByte(VoldemortOpCode.DELETE_OP_CODE);
@@ -88,7 +88,7 @@ public boolean delete(byte[] key, Version version) throws VoldemortException {
public List<Versioned<byte[]>> get(byte[] key) throws VoldemortException {
StoreUtils.assertValidKey(key);
- SocketAndStreams sands = (SocketAndStreams) pool.checkout(destination);
+ SocketAndStreams sands = pool.checkout(destination);
try {
DataOutputStream outputStream = sands.getOutputStream();
outputStream.writeByte(VoldemortOpCode.GET_OP_CODE);
@@ -120,7 +120,7 @@ public boolean delete(byte[] key, Version version) throws VoldemortException {
public void put(byte[] key, Versioned<byte[]> value) throws VoldemortException {
StoreUtils.assertValidKey(key);
- SocketAndStreams sands = (SocketAndStreams) pool.checkout(destination);
+ SocketAndStreams sands = pool.checkout(destination);
try {
DataOutputStream outputStream = sands.getOutputStream();
outputStream.writeByte(VoldemortOpCode.PUT_OP_CODE);
View
8 src/java/voldemort/utils/ByteUtils.java
@@ -422,6 +422,10 @@ public static String getString(byte[] bytes, String encoding) {
* Compare two byte arrays. Two arrays are equal if they are the same size
* and have the same contents. Otherwise b1 is smaller iff it is a prefix of
* b2 or for the first index i for which b1[i] != b2[i], b1[i] < b2[i].
+ * <p>
+ * <strong> bytes are considered unsigned. passing negative values into byte
+ * will cause them to be considered as unsigned two's complement value.
+ * </strong>
*
* @param b1 The first array
* @param b2 The second array
@@ -432,9 +436,9 @@ public static int compare(byte[] b1, byte[] b2) {
int a = (b1[i] & 0xff);
int b = (b2[j] & 0xff);
if(a != b) {
- return a - b;
+ return (a - b) / (Math.abs(a - b));
}
}
- return b1.length - b2.length;
+ return (b1.length - b2.length) / (Math.max(1, Math.abs(b1.length - b2.length)));
}
}
View
12 src/java/voldemort/versioning/VectorClock.java
@@ -116,7 +116,7 @@ public VectorClock(byte[] bytes, int offset) {
// write the number of versions
ByteUtils.writeShort(serialized, (short) versions.size(), 0);
// write the size of each version in bytes
- byte versionSize = (byte) ByteUtils.numberOfBytesRequired(getMaxVersion());
+ byte versionSize = ByteUtils.numberOfBytesRequired(getMaxVersion());
serialized[2] = versionSize;
int clockEntrySize = ByteUtils.SIZE_OF_SHORT + versionSize;
@@ -134,7 +134,7 @@ public VectorClock(byte[] bytes, int offset) {
}
public int sizeInBytes() {
- byte versionSize = (byte) ByteUtils.numberOfBytesRequired(getMaxVersion());
+ byte versionSize = ByteUtils.numberOfBytesRequired(getMaxVersion());
return ByteUtils.SIZE_OF_SHORT + 1 + this.versions.size()
* (ByteUtils.SIZE_OF_SHORT + versionSize) + ByteUtils.SIZE_OF_LONG;
}
@@ -250,18 +250,18 @@ public VectorClock merge(VectorClock clock) {
i++;
j++;
} else if(v1.getNodeId() < v2.getNodeId()) {
- newClock.versions.add((ClockEntry) v1.clone());
+ newClock.versions.add(v1.clone());
i++;
} else {
- newClock.versions.add((ClockEntry) v2.clone());
+ newClock.versions.add(v2.clone());
}
}
// Okay now there may be leftovers on one or the other list remaining
for(int k = i; k < this.versions.size(); k++)
- newClock.versions.add((ClockEntry) this.versions.get(k).clone());
+ newClock.versions.add(this.versions.get(k).clone());
for(int k = j; k < this.versions.size(); k++)
- newClock.versions.add((ClockEntry) clock.versions.get(k).clone());
+ newClock.versions.add(clock.versions.get(k).clone());
return newClock;
}
View
1  src/java/voldemort/xml/ClusterMapper.java
@@ -99,7 +99,6 @@ public Cluster readCluster(Reader input) {
}
}
- @SuppressWarnings("unchecked")
public Node readServer(Element server) {
int id = Integer.parseInt(server.getChildText(SERVER_ID_ELMT));
String host = server.getChildText(HOST_ELMT);
View
1  test/integration/voldemort/MultithreadedStressTest.java
@@ -40,7 +40,6 @@
private final int numberOfValues;
private final int numberOfRequests;
- @SuppressWarnings("unchecked")
public MultithreadedStressTest(Store<byte[], byte[]> store,
int numberOfValues,
int numberOfRequests,
View
8 test/unit/voldemort/UtilsTest.java
@@ -194,6 +194,14 @@ public void testByteComparison() {
assertEquals(-1, ByteUtils.compare(new byte[] {}, new byte[] { 1 }));
assertEquals(0, ByteUtils.compare(new byte[] { 0, 1, 2 }, new byte[] { 0, 1, 2 }));
assertEquals(-1, ByteUtils.compare(new byte[] { 0, 1, 1 }, new byte[] { 0, 1, 2 }));
+ assertEquals(-1, ByteUtils.compare(new byte[] { 0, 1, 1 }, new byte[] { 0, 1, 1, 2 }));
+ assertEquals(1, ByteUtils.compare(new byte[] { 0, 1, 2 }, new byte[] { 0, 1, 1, 1 }));
+ assertEquals(-1, ByteUtils.compare(new byte[] { 0, 1, 2 }, new byte[] { 4, 1, 1, 1 }));
+ assertEquals(1, ByteUtils.compare(new byte[] { 0, 1, 4 }, new byte[] { 0, 1, 1, 1 }));
+ assertEquals(-1, ByteUtils.compare(new byte[] { 1 }, new byte[] { -1 }));
+ assertEquals(0, ByteUtils.compare(new byte[] { -1 }, new byte[] { -1 }));
+ assertEquals(1, ByteUtils.compare(new byte[] { -1 }, new byte[] { -4 }));
+ assertEquals(-1, ByteUtils.compare(new byte[] { -4 }, new byte[] { -1 }));
}
}
View
26 test/unit/voldemort/store/bdb/BdbStorageEngineTest.java
@@ -101,4 +101,30 @@ public void testPersistence() throws Exception {
TestUtils.bytesEqual("cdef".getBytes(), vals.get(0).getValue());
}
+ public void testEquals() {
+ String name = "someName";
+ assertEquals(new BdbStorageEngine(name, environment, database),
+ new BdbStorageEngine(name, environment, database));
+ }
+
+ public void testNullConstructorParameters() {
+ try {
+ new BdbStorageEngine(null, environment, database);
+ } catch(IllegalArgumentException e) {
+ return;
+ }
+ fail("No exception thrown for null name.");
+ try {
+ new BdbStorageEngine("name", null, database);
+ } catch(IllegalArgumentException e) {
+ return;
+ }
+ fail("No exception thrown for null environment.");
+ try {
+ new BdbStorageEngine("name", environment, null);
+ } catch(IllegalArgumentException e) {
+ return;
+ }
+ fail("No exception thrown for null database.");
+ }
}
View
4 test/unit/voldemort/versioning/ClockEntryTest.java
@@ -35,8 +35,8 @@ public void testEquality() {
v2 = new ClockEntry((short) 0, (short) 2);
assertTrue(!v1.equals(v2));
- v1 = new ClockEntry((short) Short.MAX_VALUE, (short) 256);
- v2 = new ClockEntry((short) Short.MAX_VALUE, (short) 256);
+ v1 = new ClockEntry(Short.MAX_VALUE, (short) 256);
+ v2 = new ClockEntry(Short.MAX_VALUE, (short) 256);
assertEquals(v1, v2);
}
Please sign in to comment.
Something went wrong with that request. Please try again.