com.cloudtran.replicator.ssdStore
Class SSDLocalStoreImpl

java.lang.Object
  extended by com.cloudtran.replicator.ssdStore.SSDLocalStoreImpl
All Implemented Interfaces:
LocalStore

public class SSDLocalStoreImpl
extends Object
implements LocalStore

This class implements the the storage of the replicator packets onto a flash drive. The recommended implementation will use two replicator nodes each pointing to two flash drives. There will be two threads in the replicator node handling the write to the flash store. Each thread will either accumulate data to write or perform the write, which will be to both flash drives.


Field Summary
static int BLOCK_SIZE
           
static LinkedBlockingQueue<ByteArrayWriteBuffer> bufferPool
           
static int FILE_IN_USE_BACKOFF
           
static byte[] fillerArr
           
static long firstTxSeqNumInRun
           
static ConcurrentHashMap<Long,Integer> mapTxSeqNumToFileNumber
           
static ConcurrentHashMap<Long,Long> mapTxSeqNumToTxId
           
static int MAX_LOGFILE_WRITE_SIZE
           
static int MAX_NUM_FILES
           
static int N_SSD_FILES
           
static int ONE_MB
           
static boolean ONE_SSD
           
static int runNumber
           
static long runStartTimeMillis
           
static String SSD_FILE_BASE_NAME
           
static String SSD_FILE_EXTENSION
           
static int tenPercent
           
static int TOTAL_BLOCKS_PER_FILE
           
 
Fields inherited from interface com.cloudtran.replicator.localStore.LocalStore
GREEN_ZONE, RED_ZONE, YELLOW_ZONE
 
Constructor Summary
SSDLocalStoreImpl()
           
 
Method Summary
static void cleanUpBawb(ByteArrayWriteBuffer bawb)
          This is called to clean up the ByteArrayWriteBuffer and place it back on the queue
 void closeAnyOpenFiles()
           
static void completedWrite(ReplicatorOutboundRequest replicatorOutboundRequest)
          This is called from each of the SSDStoreThreads to indicate they have completed the data write
static int convertBytesToInt(byte[] byteArr, int offset)
           
static int getTenPercentOfMaxFiles()
           
static void main(String... args)
           
static int numberToRoundUp(int length)
           
 void prepareTheDisk(String ssdDirectory)
           
 void prepareTheDisks()
           
 boolean releaseOutbound(long txSeqNum)
          Releases the ReplicatorPacket stored under the txSeqNum.
 Long[] resync()
          Call this on each isolator instance when initializing replicator to set up the local store.
 Long[] resync(com.cloudtran.replicator.ssdStore.SSDLocalStoreImpl.ResyncListener resyncListener)
           
 ReplicatorPacket retrieveOutbound(long txSeqNum)
          After a resync() is called, any un-replicated packets must be sent to the remote DC.
 void startTheSSDStoreThreads()
          This starts the SSDStore Threads - this should only be called after the resync has completed
 String storeOutbound(AtomicLong txSeqNum, ReplicatorOutboundRequest replicatorOutboundRequest)
          txSeqNum is DCC.myTxSeqNum_LastSentToSSD we get to update it here This is called with a lock on it, to join updating txSeqNum and putting onto the storeQueue's, so the output to the disk is strictly ordered.
 String toString()
           
static int writeIntToBytes(int _in, ByteArrayWriteBuffer bawb, int offset)
           
static int writeLongToBytes(long _in, ByteArrayWriteBuffer bawb, int offset)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ONE_SSD

public static boolean ONE_SSD

N_SSD_FILES

public static int N_SSD_FILES

SSD_FILE_BASE_NAME

public static String SSD_FILE_BASE_NAME

SSD_FILE_EXTENSION

public static String SSD_FILE_EXTENSION

FILE_IN_USE_BACKOFF

public static int FILE_IN_USE_BACKOFF

MAX_NUM_FILES

public static final int MAX_NUM_FILES

tenPercent

public static int tenPercent

ONE_MB

public static final int ONE_MB
See Also:
Constant Field Values

MAX_LOGFILE_WRITE_SIZE

public static final int MAX_LOGFILE_WRITE_SIZE

BLOCK_SIZE

public static final int BLOCK_SIZE

TOTAL_BLOCKS_PER_FILE

public static final int TOTAL_BLOCKS_PER_FILE

fillerArr

public static final byte[] fillerArr

bufferPool

public static LinkedBlockingQueue<ByteArrayWriteBuffer> bufferPool

runNumber

public static int runNumber

runStartTimeMillis

public static long runStartTimeMillis

firstTxSeqNumInRun

public static long firstTxSeqNumInRun

mapTxSeqNumToTxId

public static ConcurrentHashMap<Long,Long> mapTxSeqNumToTxId

mapTxSeqNumToFileNumber

public static ConcurrentHashMap<Long,Integer> mapTxSeqNumToFileNumber
Constructor Detail

SSDLocalStoreImpl

public SSDLocalStoreImpl()
Method Detail

storeOutbound

public String storeOutbound(AtomicLong txSeqNum,
                            ReplicatorOutboundRequest replicatorOutboundRequest)
txSeqNum is DCC.myTxSeqNum_LastSentToSSD we get to update it here This is called with a lock on it, to join updating txSeqNum and putting onto the storeQueue's, so the output to the disk is strictly ordered. This method lays out the data structure and stores it in the ByteArrayWriteBuffer of the ReplicatorOutboundRequest. The ReplicatorOutboundRequest is then placed on the SDDLocalStoreThread (one queue per thread). The data structure of the ReplicatorOutboundRequest is as follows 4 bytes - Length of data not including CRC | Serialized SSDWriteOperationHeader | Serialized ReplicatorOutboundRequest | Serialized SSDWriteOperationTrailer | 4 byte - CRC

Specified by:
storeOutbound in interface LocalStore
replicatorOutboundRequest - ReplicatorOutboundRequest holding the packets to store. The packets include the local data center's internalTxId field for the transaction. **NB** This method must release ReplicatorOutboundRequest.finishOutboundRequestSem before returning.
Returns:
returns the String for the zone - GREEEN_ZONE, YELLOW_ZONE, RED_ZONE. If the RED_ZONE is returned, the caller must retry. Otherwise, the ReplicatorOutboundRequest has been restored. **NB** Just before returning, this method must release ror.finishOutboundRequestSem unless the RED_ZONE is returned.

completedWrite

public static void completedWrite(ReplicatorOutboundRequest replicatorOutboundRequest)
This is called from each of the SSDStoreThreads to indicate they have completed the data write

Parameters:
replicatorOutboundRequest -

cleanUpBawb

public static void cleanUpBawb(ByteArrayWriteBuffer bawb)
This is called to clean up the ByteArrayWriteBuffer and place it back on the queue

Parameters:
replicatorOutboundRequest -

releaseOutbound

public boolean releaseOutbound(long txSeqNum)
Description copied from interface: LocalStore
Releases the ReplicatorPacket stored under the txSeqNum.

Specified by:
releaseOutbound in interface LocalStore
Parameters:
txSeqNum - the transaction sequence number, as passed in storeOutbound.
Returns:
returns true if the packet was correctly stored. If false is returned the caller should retry.

startTheSSDStoreThreads

public void startTheSSDStoreThreads()
This starts the SSDStore Threads - this should only be called after the resync has completed


closeAnyOpenFiles

public void closeAnyOpenFiles()

prepareTheDisks

public void prepareTheDisks()

prepareTheDisk

public void prepareTheDisk(String ssdDirectory)

resync

public Long[] resync()
Description copied from interface: LocalStore
Call this on each isolator instance when initializing replicator to set up the local store.

Specified by:
resync in interface LocalStore
Returns:
a Long array containing (a) the first TxSeqNum to resend to the peer (b) the number of transactions to resend to the peer. Once complete, the first TxSeqNum in the new run will be the sum of these two.

resync

public Long[] resync(com.cloudtran.replicator.ssdStore.SSDLocalStoreImpl.ResyncListener resyncListener)

retrieveOutbound

public ReplicatorPacket retrieveOutbound(long txSeqNum)
Description copied from interface: LocalStore
After a resync() is called, any un-replicated packets must be sent to the remote DC. This call assumes that the resync() has been called before any further storeOutbound()/releaseOutbound() calls.

Specified by:
retrieveOutbound in interface LocalStore
Returns:
the ReplicatorPacket for the given txSeqNum.

numberToRoundUp

public static int numberToRoundUp(int length)

writeLongToBytes

public static int writeLongToBytes(long _in,
                                   ByteArrayWriteBuffer bawb,
                                   int offset)

writeIntToBytes

public static int writeIntToBytes(int _in,
                                  ByteArrayWriteBuffer bawb,
                                  int offset)

convertBytesToInt

public static int convertBytesToInt(byte[] byteArr,
                                    int offset)

toString

public String toString()
Overrides:
toString in class Object

getTenPercentOfMaxFiles

public static int getTenPercentOfMaxFiles()

main

public static void main(String... args)