Permalink
Browse files

Make recovery work better with many clients

Limit the number of parallel reads, early stop, etc..
  • Loading branch information...
1 parent cc4de96 commit 756568b0616e54a7fa6482f0ddf426b4bdfe4143 @dgomezferro committed Apr 19, 2012
View
33 src/main/java/com/yahoo/omid/client/TSOClient.java
@@ -333,8 +333,8 @@ public TSOClient(Configuration conf) throws IOException {
String host = conf.get("tso.host");
int port = conf.getInt("tso.port", 1234);
- max_retries = conf.getInt("tso.max_retries", 10);
- retry_delay_ms = conf.getInt("tso.retry_delay_ms", 3000);
+ max_retries = conf.getInt("tso.max_retries", 100);
+ retry_delay_ms = conf.getInt("tso.retry_delay_ms", 1000);
if (host == null) {
throw new IOException("tso.host missing from configuration");
@@ -359,7 +359,12 @@ private State connectIfNeeded() throws IOException {
throw e;
}
retries++;
- bootstrap.connect(addr);
+ bootstrap.connect(addr).addListener(new ChannelFutureListener() {
+ @Override
+ public void operationComplete(ChannelFuture future) throws Exception {
+ LOG.debug("Connection completed. Success: " + future.isSuccess());
+ }
+ });
state = State.CONNECTING;
return state;
}
@@ -422,6 +427,7 @@ public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) {
retries = 0;
}
clearState();
+ LOG.debug("Channel connected");
Op o = queuedOps.poll();;
while (o != null && state == State.CONNECTED) {
o.execute(channel);
@@ -442,8 +448,24 @@ private void clearState() {
public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e)
throws Exception {
synchronized(state) {
+ LOG.debug("Channel disconnected");
channel = null;
state = State.DISCONNECTED;
+ for (CreateCallback cb : createCallbacks) {
+ cb.error(new IOException("Channel Disconnected"));
+ }
+ for (CommitCallback cb : commitCallbacks.values()) {
+ cb.error(new IOException("Channel Disconnected"));
+ }
+ for (List<CommitQueryCallback> lcqb : isCommittedCallbacks.values()) {
+ for (CommitQueryCallback cqb : lcqb) {
+ cqb.error(new IOException("Channel Disconnected"));
+ }
+ }
+ createCallbacks.clear();
+ commitCallbacks.clear();
+ isCommittedCallbacks.clear();
+ connectIfNeeded();
}
}
@@ -547,13 +569,14 @@ public void exceptionCaught(ChannelHandlerContext ctx,
throws Exception {
System.out.println("Unexpected exception " + e.getCause());
e.getCause().printStackTrace();
+// e.getChannel().disconnect();
synchronized(state) {
if (state == State.CONNECTING) {
state = State.RETRY_CONNECT_WAIT;
- if (LOG.isTraceEnabled()) {
- LOG.trace("Retrying connect in " + retry_delay_ms + "ms " + retries);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Retrying connect in " + retry_delay_ms + "ms " + retries);
}
try {
retryTimer.schedule(new TimerTask() {
View
2 src/main/java/com/yahoo/omid/tso/Bucket.java
@@ -59,7 +59,7 @@ public boolean isUncommited(long id) {
return aborted;
}
- LOG.debug("Performing scanning...");
+ LOG.trace("Performing scanning...");
for (int i = transactions.nextClearBit(firstUncommited); i >= 0
&& i <= lastCommited; i = transactions.nextClearBit(i + 1)) {
View
21 src/main/java/com/yahoo/omid/tso/ClientHandler.java
@@ -19,7 +19,6 @@
import java.io.IOException;
import java.util.Collections;
import java.util.Date;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
@@ -37,8 +36,6 @@
import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
-import org.jboss.netty.channel.Channels;
-import org.jboss.netty.channel.ExceptionEvent;
import com.yahoo.omid.client.SyncAbortCompleteCallback;
import com.yahoo.omid.client.SyncCommitCallback;
@@ -161,13 +158,9 @@ public ClientHandler(Configuration conf, int nbMessage, int inflight, boolean pa
@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) {
super.channelConnected(ctx, e);
- try {
- Thread.sleep(15000);
- } catch (InterruptedException e1) {
- //ignore
- }
startDate = new Date();
channel = e.getChannel();
+ outstandingTransactions = 0;
startTransaction();
}
@@ -269,18 +262,6 @@ private long getSizeAborted() {
return aborted.size() * 8 * 8;
}
- @Override
- public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
- if (e.getCause() instanceof IOException) {
- LOG.warn("IOException from downstream.", e.getCause());
- } else {
- LOG.warn("Unexpected exception from downstream.", e.getCause());
- }
- // Offer default object
- answer.offer(false);
- Channels.close(e.getChannel());
- }
-
private java.util.Random rnd;
private boolean pauseClient;
View
7 src/main/java/com/yahoo/omid/tso/CommitHashMap.java
@@ -16,6 +16,11 @@
package com.yahoo.omid.tso;
+import java.util.Collections;
+import java.util.Set;
+
+import org.jboss.netty.util.internal.ConcurrentHashMap;
+
/**
* A hash map that uses byte[] for the key rather than longs.
*
@@ -138,7 +143,7 @@ public CommitHashMap(int initialCapacity, float loadFactor) {
// set of half aborted transactions
// TODO: set the initial capacity in a smarter way
- java.util.HashSet<Long> halfAborted = new java.util.HashSet<Long>(10000);
+ Set<Long> halfAborted = Collections.newSetFromMap(new ConcurrentHashMap<Long, Boolean>(10000));
// add a new half aborted transaction
void setHalfAborted(long startTimestamp) {
View
67 src/main/java/com/yahoo/omid/tso/TSOHandler.java
@@ -84,7 +84,6 @@
* Channel Group
*/
private ChannelGroup channelGroup = null;
- private static ChannelGroup clientChannels = new DefaultChannelGroup("clients");
private Map<Channel, ReadingBuffer> messageBuffersMap = new HashMap<Channel, ReadingBuffer>();
@@ -198,28 +197,33 @@ public void handle(TimestampRequest msg, ChannelHandlerContext ctx) {
}
ReadingBuffer buffer;
+ Channel channel = null;
+ boolean bootstrap = false;
synchronized (messageBuffersMap) {
buffer = messageBuffersMap.get(ctx.getChannel());
if (buffer == null) {
- synchronized (sharedState) {
+// synchronized (sharedState) {
synchronized (sharedMsgBufLock) {
- Channel channel = ctx.getChannel();
- channel.write(new CommittedTransactionReport(sharedState.latestStartTimestamp, sharedState.latestCommitTimestamp));
- for (Long halfAborted : sharedState.hashmap.halfAborted) {
- channel.write(new AbortedTransactionReport(halfAborted));
- }
- channel.write(new AbortedTransactionReport(sharedState.latestHalfAbortTimestamp));
- channel.write(new FullAbortReport(sharedState.latestFullAbortTimestamp));
- channel.write(new LargestDeletedTimestampReport(sharedState.largestDeletedTimestamp));
+ bootstrap = true;
+ channel = ctx.getChannel();
+ channel.write(new CommittedTransactionReport(sharedState.latestStartTimestamp.get(), sharedState.latestCommitTimestamp.get()));
+ channel.write(new AbortedTransactionReport(sharedState.latestHalfAbortTimestamp.get()));
+ channel.write(new FullAbortReport(sharedState.latestFullAbortTimestamp.get()));
+ channel.write(new LargestDeletedTimestampReport(sharedState.largestDeletedTimestamp.get()));
buffer = sharedState.sharedMessageBuffer.new ReadingBuffer(channel);
messageBuffersMap.put(channel, buffer);
channelGroup.add(channel);
- clientChannels.add(channel);
+// clientChannels.add(channel);
LOG.warn("Channel connected: " + messageBuffersMap.size());
}
- }
+// }
}
}
+ if (bootstrap) {
+ for (Long halfAborted : sharedState.hashmap.halfAborted) {
+ channel.write(new AbortedTransactionReport(halfAborted));
+ }
+ }
synchronized (sharedMsgBufLock) {
sharedState.sharedMessageBuffer.writeTimestamp(timestamp);
buffer.flush();
@@ -255,10 +259,10 @@ public void handle(CommitRequest msg, ChannelHandlerContext ctx) {
if (msg.startTimestamp < timestampOracle.first()) {
reply.committed = false;
LOG.warn("Aborting transaction after restarting TSO");
- } else if (msg.startTimestamp < sharedState.largestDeletedTimestamp) {
+ } else if (msg.startTimestamp < sharedState.largestDeletedTimestamp.get()) {
// Too old
reply.committed = false;//set as abort
-// LOG.warn("Too old starttimestamp: ST "+ msg.startTimestamp +" MAX " + sharedState.largestDeletedTimestamp);
+ LOG.warn("Too old starttimestamp: ST "+ msg.startTimestamp +" MAX " + sharedState.largestDeletedTimestamp);
} else {
//1. check the write-write conflicts
for (RowKey r: msg.rows) {
@@ -268,9 +272,9 @@ public void handle(CommitRequest msg, ChannelHandlerContext ctx) {
//System.out.println("Abort...............");
reply.committed = false;//set as abort
break;
- } else if (value == 0 && sharedState.largestDeletedTimestamp > msg.startTimestamp) {
+ } else if (value == 0 && sharedState.largestDeletedTimestamp.get() > msg.startTimestamp) {
//then it could have been committed after start timestamp but deleted by recycling
- System.out.println("Old............... " + sharedState.largestDeletedTimestamp + " " + msg.startTimestamp);
+ LOG.warn("Old............... " + sharedState.largestDeletedTimestamp + " " + msg.startTimestamp);
reply.committed = false;//set as abort
break;
}
@@ -285,12 +289,13 @@ public void handle(CommitRequest msg, ChannelHandlerContext ctx) {
//2. commit
try {
long commitTimestamp = timestampOracle.next(toWAL);
+// System.out.println(" Committing " + msg.startTimestamp + " with ts " + commitTimestamp);
sharedState.uncommited.commit(commitTimestamp);
sharedState.uncommited.commit(msg.startTimestamp);
reply.commitTimestamp = commitTimestamp;
if (msg.rows.length > 0) {
- if(LOG.isDebugEnabled()){
- LOG.debug("Adding commit to WAL");
+ if(LOG.isTraceEnabled()){
+ LOG.trace("Adding commit to WAL");
}
toWAL.writeByte(LoggerProtocol.COMMIT);
toWAL.writeLong(msg.startTimestamp);
@@ -299,18 +304,18 @@ public void handle(CommitRequest msg, ChannelHandlerContext ctx) {
for (RowKey r: msg.rows) {
// toWAL.write(r.getRow(), 0, r.getRow().length);
- sharedState.largestDeletedTimestamp = sharedState.hashmap.put(r.getRow(),
+ sharedState.largestDeletedTimestamp.set(sharedState.hashmap.put(r.getRow(),
r.getTable(),
commitTimestamp,
r.hashCode(),
- sharedState.largestDeletedTimestamp);
+ sharedState.largestDeletedTimestamp.get()));
}
sharedState.processCommit(msg.startTimestamp, commitTimestamp);
- if (sharedState.largestDeletedTimestamp > sharedState.previousLargestDeletedTimestamp) {
+ if (sharedState.largestDeletedTimestamp.get() > sharedState.previousLargestDeletedTimestamp.get()) {
toWAL.writeByte(LoggerProtocol.LARGESTDELETEDTIMESTAMP);
- toWAL.writeLong(sharedState.largestDeletedTimestamp);
- Set<Long> toAbort = sharedState.uncommited.raiseLargestDeletedTransaction(sharedState.largestDeletedTimestamp);
+ toWAL.writeLong(sharedState.largestDeletedTimestamp.get());
+ Set<Long> toAbort = sharedState.uncommited.raiseLargestDeletedTransaction(sharedState.largestDeletedTimestamp.get());
// if (!toAbort.isEmpty()) {
// LOG.warn("Slow transactions after raising max: " + toAbort);
// System.out.println("largest deleted ts: " + sharedState.largestDeletedTimestamp);
@@ -320,9 +325,9 @@ public void handle(CommitRequest msg, ChannelHandlerContext ctx) {
sharedState.hashmap.setHalfAborted(id);
queueHalfAbort(id);
}
- queueLargestIncrease(sharedState.largestDeletedTimestamp);
+ queueLargestIncrease(sharedState.largestDeletedTimestamp.get());
}
- sharedState.previousLargestDeletedTimestamp = sharedState.largestDeletedTimestamp;
+ sharedState.previousLargestDeletedTimestamp.set(sharedState.largestDeletedTimestamp.get());
}
synchronized (sharedMsgBufLock) {
queueCommit(msg.startTimestamp, commitTimestamp);
@@ -356,8 +361,8 @@ public void handle(CommitRequest msg, ChannelHandlerContext ctx) {
sharedState.nextBatch.add(cam);
if (sharedState.baos.size() >= TSOState.BATCH_SIZE) {
- if(LOG.isDebugEnabled()){
- LOG.debug("Going to add record of size " + sharedState.baos.size());
+ if(LOG.isTraceEnabled()){
+ LOG.trace("Going to add record of size " + sharedState.baos.size());
}
//sharedState.lh.asyncAddEntry(baos.toByteArray(), this, sharedState.nextBatch);
sharedState.addRecord(baos.toByteArray(),
@@ -421,8 +426,8 @@ else if (sharedState.uncommited.isUncommited(msg.queryTimestamp))
public void flush() {
synchronized (sharedState) {
- if(LOG.isDebugEnabled()){
- LOG.debug("Adding record, size: " + sharedState.baos.size());
+ if(LOG.isTraceEnabled()){
+ LOG.trace("Adding record, size: " + sharedState.baos.size());
}
sharedState.addRecord(sharedState.baos.toByteArray(), new AddRecordCallback() {
@Override
@@ -459,8 +464,8 @@ public void run() {
if (sharedState.nextBatch.size() > 0) {
synchronized (sharedState) {
if (sharedState.nextBatch.size() > 0) {
- if(LOG.isDebugEnabled()){
- LOG.debug("Flushing log batch.");
+ if(LOG.isTraceEnabled()){
+ LOG.trace("Flushing log batch.");
}
flush();
}
View
16 src/main/java/com/yahoo/omid/tso/TSOSharedMessageBuffer.java
@@ -175,8 +175,8 @@ public void writeCommit(long startTimestamp, long commitTimestamp) {
++_Coms;
++_Writes;
int readBefore = writeBuffer.readableBytes();
- long startDiff = startTimestamp - state.latestStartTimestamp;
- long commitDiff = commitTimestamp - state.latestCommitTimestamp;
+ long startDiff = startTimestamp - state.latestStartTimestamp.get();
+ long commitDiff = commitTimestamp - state.latestCommitTimestamp.get();
if (commitDiff == 1 && startDiff >= -32 && startDiff <= 31) {
++_1B;
startDiff &= 0x3f;
@@ -230,8 +230,8 @@ public void writeCommit(long startTimestamp, long commitTimestamp) {
_Avg2 += (written - _Avg2) / _Writes;
_Avg += (written - _Avg) / _Coms;
- state.latestStartTimestamp = startTimestamp;
- state.latestCommitTimestamp = commitTimestamp;
+ state.latestStartTimestamp.set(startTimestamp);
+ state.latestCommitTimestamp.set(commitTimestamp);
}
public void writeHalfAbort(long startTimestamp) {
@@ -240,7 +240,7 @@ public void writeHalfAbort(long startTimestamp) {
}
++_Writes;
int readBefore = writeBuffer.readableBytes();
- long diff = startTimestamp - state.latestHalfAbortTimestamp;
+ long diff = startTimestamp - state.latestHalfAbortTimestamp.get();
if (diff >= -16 && diff <= 15) {
writeBuffer.writeByte((byte)((diff & 0x1f) | (0x40)));
} else if (diff >= Byte.MIN_VALUE && diff <= Byte.MAX_VALUE) {
@@ -252,7 +252,7 @@ public void writeHalfAbort(long startTimestamp) {
}
++_ha;
- state.latestHalfAbortTimestamp = startTimestamp;
+ state.latestHalfAbortTimestamp.set(startTimestamp);
int written = writeBuffer.readableBytes() - readBefore;
_Avg2 += (written - _Avg2) / _Writes;
}
@@ -263,7 +263,7 @@ public void writeFullAbort(long startTimestamp) {
}
++_Writes;
int readBefore = writeBuffer.readableBytes();
- long diff = startTimestamp - state.latestFullAbortTimestamp;
+ long diff = startTimestamp - state.latestFullAbortTimestamp.get();
if (diff >= -16 && diff <= 15) {
writeBuffer.writeByte((byte)((diff & 0x1f) | (0x60)));
} else if (diff >= Byte.MIN_VALUE && diff <= Byte.MAX_VALUE) {
@@ -275,7 +275,7 @@ public void writeFullAbort(long startTimestamp) {
}
++_fa;
- state.latestFullAbortTimestamp = startTimestamp;
+ state.latestFullAbortTimestamp.set(startTimestamp);
int written = writeBuffer.readableBytes() - readBefore;
_Avg2 += (written - _Avg2) / _Writes;
}
View
42 src/main/java/com/yahoo/omid/tso/TSOState.java
@@ -20,15 +20,15 @@
import java.io.DataOutputStream;
import java.util.ArrayList;
import java.util.List;
-
-import com.yahoo.omid.tso.persistence.LoggerException.Code;
-import com.yahoo.omid.tso.persistence.BookKeeperStateBuilder;
-import com.yahoo.omid.tso.persistence.StateLogger;
-import com.yahoo.omid.tso.persistence.LoggerAsyncCallback.AddRecordCallback;
+import java.util.concurrent.atomic.AtomicLong;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import com.yahoo.omid.tso.persistence.LoggerAsyncCallback.AddRecordCallback;
+import com.yahoo.omid.tso.persistence.LoggerException.Code;
+import com.yahoo.omid.tso.persistence.StateLogger;
+
/**
* The wrapper for different states of TSO
@@ -103,12 +103,12 @@ protected TimestampOracle getSO(){
/**
* Largest Deleted Timestamp
*/
- public long largestDeletedTimestamp = 0;
- public long previousLargestDeletedTimestamp = 0;
- public long latestCommitTimestamp = 0;
- public long latestStartTimestamp = 0;
- public long latestHalfAbortTimestamp = 0;
- public long latestFullAbortTimestamp = 0;
+ public AtomicLong largestDeletedTimestamp = new AtomicLong();
+ public AtomicLong previousLargestDeletedTimestamp = new AtomicLong();
+ public AtomicLong latestCommitTimestamp = new AtomicLong();
+ public AtomicLong latestStartTimestamp = new AtomicLong();
+ public AtomicLong latestHalfAbortTimestamp = new AtomicLong();
+ public AtomicLong latestFullAbortTimestamp = new AtomicLong();
public TSOSharedMessageBuffer sharedMessageBuffer = new TSOSharedMessageBuffer(this);
@@ -125,8 +125,8 @@ protected TimestampOracle getSO(){
*
* @param startTimestamp
*/
- protected void processCommit(long startTimestamp, long commitTimestamp){
- largestDeletedTimestamp = hashmap.setCommitted(startTimestamp, commitTimestamp, largestDeletedTimestamp);
+ protected synchronized void processCommit(long startTimestamp, long commitTimestamp){
+ largestDeletedTimestamp.set(hashmap.setCommitted(startTimestamp, commitTimestamp, largestDeletedTimestamp.get()));
}
/**
@@ -135,15 +135,15 @@ protected void processCommit(long startTimestamp, long commitTimestamp){
* @param largestDeletedTimestamp
*/
protected synchronized void processLargestDeletedTimestamp(long largestDeletedTimestamp){
- this.largestDeletedTimestamp = Math.max(largestDeletedTimestamp, this.largestDeletedTimestamp);
+ this.largestDeletedTimestamp.set(Math.max(largestDeletedTimestamp, this.largestDeletedTimestamp.get()));
}
/**
* Process abort request.
*
* @param startTimestamp
*/
- protected void processAbort(long startTimestamp){
+ protected synchronized void processAbort(long startTimestamp){
hashmap.setHalfAborted(startTimestamp);
uncommited.abort(startTimestamp);
}
@@ -153,7 +153,7 @@ protected void processAbort(long startTimestamp){
*
* @param startTimestamp
*/
- protected void processFullAbort(long startTimestamp){
+ protected synchronized void processFullAbort(long startTimestamp){
hashmap.setFullAborted(startTimestamp);
}
@@ -191,16 +191,14 @@ void stop(){
public TSOState(StateLogger logger, TimestampOracle timestampOracle) {
this.timestampOracle = timestampOracle;
- this.largestDeletedTimestamp = this.previousLargestDeletedTimestamp = this.timestampOracle.get();
- this.uncommited = new Uncommited(largestDeletedTimestamp);
+ this.previousLargestDeletedTimestamp.set(this.timestampOracle.get());
+ this.largestDeletedTimestamp.set(this.previousLargestDeletedTimestamp.get());
+ this.uncommited = new Uncommited(largestDeletedTimestamp.get());
this.logger = logger;
}
public TSOState(TimestampOracle timestampOracle) {
- this.timestampOracle = timestampOracle;
- this.largestDeletedTimestamp = this.previousLargestDeletedTimestamp = timestampOracle.get();
- this.uncommited = new Uncommited(largestDeletedTimestamp);
- this.logger = null;
+ this(null, timestampOracle);
}
}
View
48 src/main/java/com/yahoo/omid/tso/ThroughputMonitor.java
@@ -79,7 +79,7 @@ public void run() {
long oldOverflow = TSOSharedMessageBuffer._overflows;
for (;;) {
- Thread.sleep(3000);
+ Thread.sleep(1000);
long endTime = System.currentTimeMillis();
long newCounter = TSOHandler.getTransferredBytes();
@@ -156,32 +156,32 @@ public void run() {
// TSOSharedMessageBuffer._avgLT,
TSOPipelineFactory.bwhandler != null ? TSOPipelineFactory.bwhandler.getBytesReceivedPerSecond() / (double) (1024 * 1024) : 0,
TSOPipelineFactory.bwhandler != null ? TSOPipelineFactory.bwhandler.getBytesSentPerSecond() / (double) (1024 * 1024) : 0,
- state.largestDeletedTimestamp
+ state.largestDeletedTimestamp.get()
// Arrays.toString(TSOSharedMessageBuffer.freq)
)
);
- LOG.trace(String.format("SERVER: %4.3f TPS, %4.6f Abort/s "
- + "Co: %2.2f Ha: %2.2f Fa: %2.2f Li: %2.2f Avg commit: %2.4f Avg flush: %5.2f "
- + "Avg write: %5.2f Tot overflows: %d Tot flushes: %d Tot empty flu: %d "
- + "Queries: %d CurrentBuffers: %d ExtraGets: %d AskedTSO: %d",
- (newCounter - oldCounter) / (float)(endTime - startTime) * 1000,
- (newAbortCount - oldAbortCount) / (float)(endTime - startTime) * 1000,
- (newComs - oldComs) / (float)(newWrites - oldWrites) * 100,
- (newHa - oldHa) / (float)(newWrites - oldWrites) * 100,
- (newFa - oldFa) / (float)(newWrites - oldWrites) * 100,
- (newLi - oldLi) / (float)(newWrites - oldWrites) * 100,
- avg,
- (newflusheSize - oldflusheSize) / (float)(newflushes - oldflushes),
- avg2,
- newOverflow - oldOverflow,
- (newflushes - oldflushes),
- newEmptyFlushes - oldEmptyFlushes,
-
- newQueries - oldQueries,
- TSOBuffer.nBuffers,
- newExtraGetsPerformed - oldExtraGetsPerformed,
- newAskedTSO - oldAskedTSO)
- );
+// LOG.trace(String.format("SERVER: %4.3f TPS, %4.6f Abort/s "
+// + "Co: %2.2f Ha: %2.2f Fa: %2.2f Li: %2.2f Avg commit: %2.4f Avg flush: %5.2f "
+// + "Avg write: %5.2f Tot overflows: %d Tot flushes: %d Tot empty flu: %d "
+// + "Queries: %d CurrentBuffers: %d ExtraGets: %d AskedTSO: %d",
+// (newCounter - oldCounter) / (float)(endTime - startTime) * 1000,
+// (newAbortCount - oldAbortCount) / (float)(endTime - startTime) * 1000,
+// (newComs - oldComs) / (float)(newWrites - oldWrites) * 100,
+// (newHa - oldHa) / (float)(newWrites - oldWrites) * 100,
+// (newFa - oldFa) / (float)(newWrites - oldWrites) * 100,
+// (newLi - oldLi) / (float)(newWrites - oldWrites) * 100,
+// avg,
+// (newflusheSize - oldflusheSize) / (float)(newflushes - oldflushes),
+// avg2,
+// newOverflow - oldOverflow,
+// (newflushes - oldflushes),
+// newEmptyFlushes - oldEmptyFlushes,
+//
+// newQueries - oldQueries,
+// TSOBuffer.nBuffers,
+// newExtraGetsPerformed - oldExtraGetsPerformed,
+// newAskedTSO - oldAskedTSO)
+// );
// if (TSOPipelineFactory.bwhandler != null) {
// TSOPipelineFactory.bwhandler.reset();
// }
View
9 src/main/java/com/yahoo/omid/tso/TimestampOracle.java
@@ -61,9 +61,10 @@
public long next(DataOutputStream toWal) throws IOException {
last++;
if (last >= maxTimestamp) {
- toWal.writeByte(LoggerProtocol.TIMESTAMPORACLE);
- toWal.writeLong(last);
maxTimestamp += TIMESTAMP_BATCH;
+ toWal.writeByte(LoggerProtocol.TIMESTAMPORACLE);
+ toWal.writeLong(maxTimestamp);
+ LOG.warn("Loggin timestamporacle " + maxTimestamp);
}
if(LOG.isTraceEnabled()){
LOG.trace("Next timestamp: " + last);
@@ -106,8 +107,8 @@ public void initialize(){
*/
public void initialize(long timestamp){
LOG.info("Initializing timestamp oracle");
- this.last = this.first = Math.max(this.last, TIMESTAMP_BATCH);
- maxTimestamp = this.first;
+ this.last = this.first = Math.max(this.last, timestamp + TIMESTAMP_BATCH);
+ maxTimestamp = this.first; // max timestamp will be persisted
LOG.info("First: " + this.first + ", Last: " + this.last);
initialize();
}
View
1 src/main/java/com/yahoo/omid/tso/Uncommited.java
@@ -44,6 +44,7 @@ public Uncommited(long startTimestamp) {
}
public synchronized void commit(long id) {
+// System.out.println("Committing uncommitted " + id);
if (log && id < first_start) {
System.out.println("id: " + id);
Thread.dumpStack();
View
5 src/main/java/com/yahoo/omid/tso/messages/MinimumTimestamp.java
@@ -16,4 +16,9 @@ public long getTimestamp() {
return timestamp;
}
+ @Override
+ public String toString() {
+ return "{MinimumTimestamp " + timestamp + "}";
+ }
+
}
View
11 src/main/java/com/yahoo/omid/tso/persistence/BookKeeperStateBuilder.java
@@ -23,6 +23,7 @@
import java.nio.ByteBuffer;
import java.util.Enumeration;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Semaphore;
import org.apache.bookkeeper.client.AsyncCallback.OpenCallback;
import org.apache.bookkeeper.client.AsyncCallback.ReadCallback;
@@ -73,6 +74,7 @@
* It provides a good degree of parallelism.
*/
private static final long BKREADBATCHSIZE = 50;
+ private static final int PARALLEL_READS = 4;
public static TSOState getState(TSOServerConfig config){
TSOState returnValue;
@@ -99,11 +101,13 @@ public static TSOState getState(TSOServerConfig config){
ZooKeeper zk;
LoggerProtocol lp;
boolean enabled;
+ Semaphore throttleReads;
TSOServerConfig config;
BookKeeperStateBuilder(TSOServerConfig config) {
this.timestampOracle = new TimestampOracle();
this.config = config;
+ this.throttleReads = new Semaphore(PARALLEL_READS);
}
/**
@@ -205,6 +209,7 @@ public void processResult(int rc, String path, Object ctx, byte[] data, Stat sta
*/
class LoggerExecutor implements ReadCallback {
public void readComplete(int rc, LedgerHandle lh, Enumeration<LedgerEntry> entries, Object ctx){
+ throttleReads.release();
if(rc != BKException.Code.OK){
LOG.error("Error while reading ledger entries." + BKException.getMessage(rc));
((BookKeeperStateBuilder.Context) ctx).setState(null);
@@ -343,6 +348,12 @@ public void openComplete(int rc, LedgerHandle lh, Object ctx){
} else {
long counter = lh.getLastAddConfirmed();
while(counter >= 0){
+ try {
+ throttleReads.acquire();
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ if (((Context) ctx).isReady()) break;
long nextBatch = Math.max(counter - BKREADBATCHSIZE + 1, 0);
lh.asyncReadEntries(nextBatch, counter, new LoggerExecutor(), ctx);
counter -= BKREADBATCHSIZE;
View
13 src/main/java/com/yahoo/omid/tso/persistence/LoggerProtocol.java
@@ -48,14 +48,16 @@
super(timestampOracle);
}
+ private boolean commits;
+ private boolean oracle;
+
/**
* Execute a logged entry (several logged ops)
* @param bb Serialized operations
* @return true if the recovery is finished
*/
- boolean execute(ByteBuffer bb){
+ synchronized boolean execute(ByteBuffer bb){
boolean done = !bb.hasRemaining();
- boolean recovered = false;
while(!done){
byte op = bb.get();
long timestamp, startTimestamp, commitTimestamp;
@@ -66,13 +68,14 @@ boolean execute(ByteBuffer bb){
case TIMESTAMPORACLE:
timestamp = bb.getLong();
this.getSO().initialize(timestamp);
+ oracle = true;
break;
case COMMIT:
startTimestamp = bb.getLong();
commitTimestamp = bb.getLong();
processCommit(startTimestamp, commitTimestamp);
- if (commitTimestamp < largestDeletedTimestamp) {
- recovered = true;
+ if (commitTimestamp < largestDeletedTimestamp.get()) {
+ commits = true;
}
break;
case LARGESTDELETEDTIMESTAMP:
@@ -93,7 +96,7 @@ boolean execute(ByteBuffer bb){
}
if(bb.remaining() == 0) done = true;
}
- return recovered;
+ return oracle && commits;
}
/**
View
1 src/test/java/com/yahoo/omid/TestCompaction.java
@@ -35,6 +35,7 @@
import com.yahoo.omid.client.TransactionManager;
import com.yahoo.omid.client.TransactionState;
import com.yahoo.omid.client.TransactionalTable;
+import com.yahoo.omid.tso.TSOState;
public class TestCompaction extends OmidTestBase {
private static final Log LOG = LogFactory.getLog(TestCompaction.class);
View
2 src/test/java/com/yahoo/omid/tso/TestCommitQuery.java
@@ -82,7 +82,7 @@ public void testCommitQuery() throws Exception {
TimestampResponse tr3 = clientHandler.receiveMessage(TimestampResponse.class);
assertTrue(tr3.timestamp > tr2.timestamp);
- state.largestDeletedTimestamp = 1000000;
+ state.largestDeletedTimestamp.set(1000000);
//
// Test Commit query of half aborted transaction

0 comments on commit 756568b

Please sign in to comment.