org.eclipse.jgit.storage.dht.spi.cache
Class CacheChunkTable

java.lang.Object
  extended by org.eclipse.jgit.storage.dht.spi.cache.CacheChunkTable
All Implemented Interfaces:
ChunkTable

public class CacheChunkTable
extends java.lang.Object
implements ChunkTable

Cache wrapper around ChunkTable.


Constructor Summary
CacheChunkTable(ChunkTable dbTable, CacheDatabase cacheDatabase)
          Initialize a new wrapper.
 
Method Summary
 void get(Context options, java.util.Set<ChunkKey> keys, AsyncCallback<java.util.Collection<PackChunk.Members>> callback)
          Asynchronously load one or more chunks
 void getMeta(Context options, java.util.Set<ChunkKey> keys, AsyncCallback<java.util.Map<ChunkKey,GitStore.ChunkMeta>> callback)
          Asynchronously load one or more chunk meta fields.
 void put(PackChunk.Members chunk, WriteBuffer buffer)
          Put some (or all) of a single chunk.
 void remove(ChunkKey key, WriteBuffer buffer)
          Completely remove a chunk and all of its data elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheChunkTable

public CacheChunkTable(ChunkTable dbTable,
                       CacheDatabase cacheDatabase)
Initialize a new wrapper.

Parameters:
dbTable - the underlying database's corresponding table.
cacheDatabase - the cache database.
Method Detail

get

public void get(Context options,
                java.util.Set<ChunkKey> keys,
                AsyncCallback<java.util.Collection<PackChunk.Members>> callback)
Description copied from interface: ChunkTable
Asynchronously load one or more chunks

Callers are responsible for breaking up very large collections of chunk keys into smaller units, based on the reader's batch size option. Since chunks typically 1 MB each, 10-20 keys is a reasonable batch size, but depends on available JVM memory and performance of this method obtaining chunks from the database.

Specified by:
get in interface ChunkTable
Parameters:
options - options to control reading.
keys - the chunk keys to obtain.
callback - receives the results when ready. If this is an instance of StreamingCallback, implementors should try to deliver results early.

getMeta

public void getMeta(Context options,
                    java.util.Set<ChunkKey> keys,
                    AsyncCallback<java.util.Map<ChunkKey,GitStore.ChunkMeta>> callback)
Description copied from interface: ChunkTable
Asynchronously load one or more chunk meta fields.

Usually meta is loaded by ChunkTable.get(Context, Set, AsyncCallback), but some uses may require looking up the fragment data without having the entire chunk.

Specified by:
getMeta in interface ChunkTable
Parameters:
options - options to control reading.
keys - the chunk keys to obtain.
callback - receives the results when ready. If this is an instance of StreamingCallback, implementors should try to deliver results early.

put

public void put(PackChunk.Members chunk,
                WriteBuffer buffer)
         throws DhtException
Description copied from interface: ChunkTable
Put some (or all) of a single chunk.

The higher level storage layer typically stores chunks in pieces. Its common to first store the data, then much later store the fragments and index. Sometimes all of the members are ready at once, and can be put together as a single unit. This method handles both approaches to storing a chunk.

Implementors must use a partial writing approach, for example:

   ColumnUpdateList list = ...;
   if (chunk.getChunkData() != null)
     list.addColumn("chunk_data", chunk.getChunkData());
   if (chunk.getChunkIndex() != null)
     list.addColumn("chunk_index", chunk.getChunkIndex());
   if (chunk.getFragments() != null)
     list.addColumn("fragments", chunk.getFragments());
   createOrUpdateRow(chunk.getChunkKey(), list);
 

Specified by:
put in interface ChunkTable
Parameters:
chunk - description of the chunk to be stored.
buffer - buffer to enqueue the put onto.
Throws:
DhtException - if the buffer flushed and an enqueued operation failed.

remove

public void remove(ChunkKey key,
                   WriteBuffer buffer)
            throws DhtException
Description copied from interface: ChunkTable
Completely remove a chunk and all of its data elements.

Chunk removal should occur as quickly as possible after the flush has completed, as the caller has already ensured the chunk is not in use.

Specified by:
remove in interface ChunkTable
Parameters:
key - key of the chunk to remove.
buffer - buffer to enqueue the remove onto.
Throws:
DhtException - if the buffer flushed and an enqueued operation failed.


Copyright © 2011. All Rights Reserved.