org.sdnplatform.sync.internal
Class SyncManager

java.lang.Object
  extended by org.sdnplatform.sync.internal.AbstractSyncManager
      extended by org.sdnplatform.sync.internal.SyncManager
All Implemented Interfaces:
IFloodlightModule, IFloodlightService, ISyncService

public class SyncManager
extends AbstractSyncManager

Implementation for ISyncService that keeps local copies of the data and will synchronize it to other nodes in the cluster

Author:
readams
See Also:
ISyncService

Nested Class Summary
protected  class SyncManager.AntientropyTask
          Periodically perform antientropy
protected  class SyncManager.CleanupTask
          Periodically perform cleanup
protected  class SyncManager.HintWorker
          Worker thread that will drain the sync item queue and write the appropriate messages to the node I/O channels
protected  class SyncManager.UpdateConfigTask
          Worker task to periodically rescan the configuration
 
Nested classes/interfaces inherited from interface org.sdnplatform.sync.ISyncService
ISyncService.Scope
 
Field Summary
static IDebugCounter counterErrorProcessing
           
static IDebugCounter counterErrorRemote
           
static IDebugCounter counterGets
           
static IDebugCounter counterHints
          Debug Counters
static IDebugCounter counterIterators
           
static IDebugCounter counterPuts
           
static IDebugCounter counterReceivedValues
           
static IDebugCounter counterSentValues
           
protected  IDebugCounterService debugCounter
           
protected static org.slf4j.Logger logger
           
protected  RPCService rpcService
           
protected  IThreadPoolService threadPool
           
 
Constructor Summary
SyncManager()
           
 
Method Summary
 void addListener(java.lang.String storeName, MappingStoreListener listener)
          Add a listener to the specified store
 void antientropy()
          Communicate with a random node and do a full synchronization of the all the stores on each node that have the appropriate scope.
 void antientropy(Node node)
          Perform a synchronization with the node specified
 void cleanup()
          Perform periodic scheduled cleanup.
 void closeCursor(Cursor cursor)
          Close the given cursor and remove it from the map
protected  void doUpdateConfiguration()
           
 ClusterConfig getClusterConfig()
          Get the cluster configuration object
 Cursor getCursor(int cursorId)
          Retrieve the cursor, if any, for the given cursor ID
 short getLocalNodeId()
          Get the local ID of the local node
 java.util.Collection<java.lang.Class<? extends IFloodlightService>> getModuleDependencies()
          Get a list of Modules that this module depends on.
 IStorageEngine<ByteArray,byte[]> getRawStore(java.lang.String storeName)
          Get access to the raw storage engine.
 IStore<ByteArray,byte[]> getStore(java.lang.String storeName)
          Get a store object corresponding to the given store name
protected  SynchronizingStorageEngine getStoreInternal(java.lang.String storeName)
           
 IThreadPoolService getThreadPool()
          Return the threadpool
 boolean handleSyncOffer(java.lang.String storeName, byte[] key, java.lang.Iterable<VectorClock> versions)
          Check whether any of the specified versions for the key are not older than the versions we already have
 void init(FloodlightModuleContext context)
          This is a hook for each module to do its internal initialization, e.g., call setService(context.getService("Service")) All module dependencies are resolved when this is called, but not every module is initialized.
 Cursor newCursor(java.lang.String storeName)
          Allocate a new cursor for the given store name
 void queueSyncTask(SynchronizingStorageEngine e, ByteArray key, Versioned<byte[]> value)
          Queue a synchronization of the specified KeyedValues to all nodes assocatiated with the storage engine specified
 void registerPersistentStore(java.lang.String storeName, ISyncService.Scope scope)
          Create a store with the given store name and scope that will be persistent across reboots.
 void registerStore(java.lang.String storeName, ISyncService.Scope scope)
          Create a store with the given store name and scope
 void shutdown()
          Shut down the sync manager.
 void startUp(FloodlightModuleContext context)
          This is a hook for each module to do its external initializations, e.g., register for callbacks or query for state in other modules It is expected that this function will not block and that modules that want non-event driven CPU will spawn their own threads.
 void updateConfiguration()
          Update the node configuration to add or remove nodes
 void writeSyncValue(java.lang.String storeName, ISyncService.Scope scope, boolean persist, byte[] key, java.lang.Iterable<Versioned<byte[]>> values)
          Write a value synchronized from another node, bypassing some of the usual logic when a client writes data.
 
Methods inherited from class org.sdnplatform.sync.internal.AbstractSyncManager
getModuleServices, getServiceImpls, getStoreClient, getStoreClient, getStoreClient, getStoreClient, getStoreClient
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final org.slf4j.Logger logger

threadPool

protected IThreadPoolService threadPool

debugCounter

protected IDebugCounterService debugCounter

rpcService

protected RPCService rpcService

counterHints

public static IDebugCounter counterHints
Debug Counters


counterSentValues

public static IDebugCounter counterSentValues

counterReceivedValues

public static IDebugCounter counterReceivedValues

counterPuts

public static IDebugCounter counterPuts

counterGets

public static IDebugCounter counterGets

counterIterators

public static IDebugCounter counterIterators

counterErrorRemote

public static IDebugCounter counterErrorRemote

counterErrorProcessing

public static IDebugCounter counterErrorProcessing
Constructor Detail

SyncManager

public SyncManager()
Method Detail

registerStore

public void registerStore(java.lang.String storeName,
                          ISyncService.Scope scope)
Description copied from interface: ISyncService
Create a store with the given store name and scope

Parameters:
storeName - the name of the store
scope - the distribution scope for the data

registerPersistentStore

public void registerPersistentStore(java.lang.String storeName,
                                    ISyncService.Scope scope)
                             throws PersistException
Description copied from interface: ISyncService
Create a store with the given store name and scope that will be persistent across reboots. The performance will be dramatically slower

Parameters:
storeName - the name of the store
scope - the distribution scope for the data
Throws:
PersistException

getClusterConfig

public ClusterConfig getClusterConfig()
Get the cluster configuration object

Returns:
the ClusterConfig object
See Also:
ClusterConfig

cleanup

public void cleanup()
             throws SyncException
Perform periodic scheduled cleanup. Note that this will be called automatically and you shouldn't generally call it directly except for testing

Throws:
SyncException

antientropy

public void antientropy(Node node)
Perform a synchronization with the node specified


antientropy

public void antientropy()
Communicate with a random node and do a full synchronization of the all the stores on each node that have the appropriate scope.


writeSyncValue

public void writeSyncValue(java.lang.String storeName,
                           ISyncService.Scope scope,
                           boolean persist,
                           byte[] key,
                           java.lang.Iterable<Versioned<byte[]>> values)
                    throws PersistException
Write a value synchronized from another node, bypassing some of the usual logic when a client writes data. If the store is not known, this will automatically register it

Parameters:
storeName - the store name
scope - the scope for the store
persist - TODO
key - the key to write
values - a list of versions for the key to write
Throws:
PersistException

handleSyncOffer

public boolean handleSyncOffer(java.lang.String storeName,
                               byte[] key,
                               java.lang.Iterable<VectorClock> versions)
                        throws SyncException
Check whether any of the specified versions for the key are not older than the versions we already have

Parameters:
storeName - the store to check
key - the key to check
versions - an iterable over the versions
Returns:
true if we'd like a copy of the data indicated
Throws:
SyncException

getRawStore

public IStorageEngine<ByteArray,byte[]> getRawStore(java.lang.String storeName)
                                             throws UnknownStoreException
Get access to the raw storage engine. This is useful for some on-the-wire communication

Parameters:
storeName - the store name to get
Returns:
the IStorageEngine
Throws:
UnknownStoreException

getThreadPool

public IThreadPoolService getThreadPool()
Return the threadpool

Returns:
the IThreadPoolService

queueSyncTask

public void queueSyncTask(SynchronizingStorageEngine e,
                          ByteArray key,
                          Versioned<byte[]> value)
Queue a synchronization of the specified KeyedValues to all nodes assocatiated with the storage engine specified

Parameters:
e - the storage engine for the values
kv - the values to synchronize

addListener

public void addListener(java.lang.String storeName,
                        MappingStoreListener listener)
                 throws UnknownStoreException
Description copied from class: AbstractSyncManager
Add a listener to the specified store

Specified by:
addListener in class AbstractSyncManager
Parameters:
storeName - the name of the store
listener - the listener to add
Throws:
UnknownStoreException

updateConfiguration

public void updateConfiguration()
Update the node configuration to add or remove nodes

Throws:
FloodlightModuleException

getCursor

public Cursor getCursor(int cursorId)
Retrieve the cursor, if any, for the given cursor ID

Parameters:
cursorId - the cursor ID
Returns:
the Cursor

newCursor

public Cursor newCursor(java.lang.String storeName)
                 throws UnknownStoreException
Allocate a new cursor for the given store name

Parameters:
storeName - the store name
Returns:
the Cursor
Throws:
SyncException
UnknownStoreException

closeCursor

public void closeCursor(Cursor cursor)
Close the given cursor and remove it from the map

Parameters:
cursor - the cursor to close

getStore

public IStore<ByteArray,byte[]> getStore(java.lang.String storeName)
                                  throws UnknownStoreException
Description copied from class: AbstractSyncManager
Get a store object corresponding to the given store name

Specified by:
getStore in class AbstractSyncManager
Parameters:
storeName - the store name
Returns:
the IStore
Throws:
UnknownStoreException

getLocalNodeId

public short getLocalNodeId()
Description copied from class: AbstractSyncManager
Get the local ID of the local node

Specified by:
getLocalNodeId in class AbstractSyncManager
Returns:
the node ID

shutdown

public void shutdown()
Description copied from class: AbstractSyncManager
Shut down the sync manager. Tear down any communicating threads

Specified by:
shutdown in class AbstractSyncManager

init

public void init(FloodlightModuleContext context)
          throws FloodlightModuleException
Description copied from interface: IFloodlightModule
This is a hook for each module to do its internal initialization, e.g., call setService(context.getService("Service")) All module dependencies are resolved when this is called, but not every module is initialized.

Throws:
FloodlightModuleException

startUp

public void startUp(FloodlightModuleContext context)
             throws FloodlightModuleException
Description copied from interface: IFloodlightModule
This is a hook for each module to do its external initializations, e.g., register for callbacks or query for state in other modules It is expected that this function will not block and that modules that want non-event driven CPU will spawn their own threads.

Throws:
FloodlightModuleException

getModuleDependencies

public java.util.Collection<java.lang.Class<? extends IFloodlightService>> getModuleDependencies()
Description copied from interface: IFloodlightModule
Get a list of Modules that this module depends on. The module system will ensure that each these dependencies is resolved before the subsequent calls to init().

Returns:
The Collection of IFloodlightServices that this module depends on.

doUpdateConfiguration

protected void doUpdateConfiguration()
                              throws FloodlightModuleException
Throws:
FloodlightModuleException

getStoreInternal

protected SynchronizingStorageEngine getStoreInternal(java.lang.String storeName)
                                               throws UnknownStoreException
Throws:
UnknownStoreException