Project

General

Profile

Idea #3705

Updated by Tim Pierce over 9 years ago

Both the trash collector and pull manager should be implemented by a common BlockManager package.    A BlockManager runs concurrently with Keepstore, and is responsible for maintaining a list of blocks that require outstanding attention (for trash collector, deleting; for pull manager, replicating). 

 A @BlockWorker@ is a type defined as @func(interface{})@ i.e. a function that takes a single generic object as its argument.    Note that a BlockWorker function is responsible for casting its argument to the appropriate type for whatever action needs to be taken. 

 The BlockManager interface provides these methods: 
 * @Start(BlockWorker)@ 
 ** Launches a concurrent listener that waits for a new block list to be delivered via @SetList()@. The listener loops over the list and applies the @BlockWorker@ function to each block. 
 * @SetList(container.List)@ 
 ** Delivers a new block list to the listener. Upon receipt of the new list, the listener replaces any existing list and with the new one, discarding any unprocessed requests, and begins processing it. 
 * @GetList()@ 
 ** Returns the listener's current block list. 
 * @Close()@ 
 ** Shuts down the listener. 

 Two different BlockManager objects are distinguished by: 
 * The @BlockWorker@ function that processes each item. 
 * The type of block action request that is stored in the block list passed to SetList(). 

 For example, to implement a trash collector: 
 <pre> 
 type DeleteRequest struct { 
     blockhash string 
     expires time.Time 
 } 

 func DeleteBlock (item interface{}) { 
     var r DeleteRequest 
     if r, ok := item.(DeleteRequest); ok { 
         vol.Delete(r.blockhash) 
     } 
 } 

 trash := block_manager.New() 
 trash.Start(DeleteBlock) 
 trash.SetList(blocks_to_delete) 
 </pre> 

Back