Skip to content

Commit

Permalink
Clarify alignment field in store copy protocol
Browse files Browse the repository at this point in the history
Rename the 'recordSize' to 'requiredElementAlignment' in the store copy protocol, to abstract ourselves from the fact that we occasionally copy over record stores with that code.
The code is mean to be generic, and is indeed used to copy over other files, such as indexes and logs, and an element alignment requirement is a generic term for what we want.
  • Loading branch information
chrisvest committed Sep 19, 2016
1 parent 5d55bb0 commit b35370a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
Expand Up @@ -345,10 +345,10 @@ private StoreWriter decorateWithProgressIndicator( final StoreWriter actual )


@Override @Override
public long write( String path, ReadableByteChannel data, ByteBuffer temporaryBuffer, public long write( String path, ReadableByteChannel data, ByteBuffer temporaryBuffer,
boolean hasData, int recordSize ) throws IOException boolean hasData, int requiredElementAlignment ) throws IOException
{ {
log.info( "Copying %s", path ); log.info( "Copying %s", path );
long written = actual.write( path, data, temporaryBuffer, hasData, recordSize ); long written = actual.write( path, data, temporaryBuffer, hasData, requiredElementAlignment );
log.info( "Copied %s %s", path, bytes( written ) ); log.info( "Copied %s %s", path, bytes( written ) );
totalFiles++; totalFiles++;
return written; return written;
Expand Down
Expand Up @@ -26,11 +26,17 @@


public interface StoreWriter extends Closeable public interface StoreWriter extends Closeable
{ {
// "hasData" is an effect of the block format not supporting a zero length block /**
// whereas a neostore file may actually be 0 bytes we'll have to keep track * Pipe the data from the given {@link ReadableByteChannel} to a location given by the {@code path}, using the
// of that special case. * given {@code temporaryBuffer} for buffering if necessary.
long write( String path, ReadableByteChannel data, ByteBuffer temporaryBuffer, boolean hasData, int recordSize ) * The {@code hasData} is an effect of the block format not supporting a zero length blocks, whereas a neostore
throws IOException; * file may actually be 0 bytes we'll have to keep track of that special case.
* The {@code requiredElementAlignment} parameter specifies the size in bytes to which the transferred elements
* should be aligned. For record store files, this is the record size. For files that have no special alignment
* requirements, you should use the value {@code 1} to signify that any alignment will do.
*/
long write( String path, ReadableByteChannel data, ByteBuffer temporaryBuffer, boolean hasData,
int requiredElementAlignment ) throws IOException;


@Override @Override
void close(); void close();
Expand Down
Expand Up @@ -55,7 +55,7 @@ public ToFileStoreWriter( File graphDbStoreDir, StoreCopyClient.Monitor monitor,


@Override @Override
public long write( String path, ReadableByteChannel data, ByteBuffer temporaryBuffer, boolean hasData, public long write( String path, ReadableByteChannel data, ByteBuffer temporaryBuffer, boolean hasData,
int recordSize ) throws IOException int requiredElementAlignment ) throws IOException
{ {
try try
{ {
Expand All @@ -73,7 +73,7 @@ public long write( String path, ReadableByteChannel data, ByteBuffer temporaryBu
// The reason is that we are copying to a temporary store location, and then we'll move the files later. // The reason is that we are copying to a temporary store location, and then we'll move the files later.
if ( storeType.isPresent() && storeType.get().isRecordStore() ) if ( storeType.isPresent() && storeType.get().isRecordStore() )
{ {
int filePageSize = filePageSize( recordSize ); int filePageSize = filePageSize( requiredElementAlignment );
try ( PagedFile pagedFile = pageCache.map( file, filePageSize, CREATE, WRITE ) ) try ( PagedFile pagedFile = pageCache.map( file, filePageSize, CREATE, WRITE ) )
{ {
final long written = writeDataThroughPageCache( pagedFile, data, temporaryBuffer, hasData ); final long written = writeDataThroughPageCache( pagedFile, data, temporaryBuffer, hasData );
Expand Down Expand Up @@ -102,11 +102,13 @@ private void addPageCacheMoveAction( File file )
pageCache.renameFile( file, new File( toDir, file.getName() ), copyOptions ) ) ); pageCache.renameFile( file, new File( toDir, file.getName() ), copyOptions ) ) );
} }


private int filePageSize( int recordSize ) private int filePageSize( int alignment )
{ {
// We know we are dealing with a record store at this point, so the required alignment is the record size,
// and we can use this to do the page size calculation in the same way as the stores would.
final int pageCacheSize = pageCache.pageSize(); final int pageCacheSize = pageCache.pageSize();
return (recordSize == NO_RECORD_SIZE) ? pageCacheSize return (alignment == NO_RECORD_SIZE) ? pageCacheSize
: (pageCacheSize - (pageCacheSize % recordSize)); : (pageCacheSize - (pageCacheSize % alignment));
} }


private long writeDataThroughFileSystem( File file, ReadableByteChannel data, ByteBuffer temporaryBuffer, private long writeDataThroughFileSystem( File file, ReadableByteChannel data, ByteBuffer temporaryBuffer,
Expand Down
Expand Up @@ -45,7 +45,7 @@ public ToNetworkStoreWriter( ChannelBuffer targetBuffer, Monitors monitors )


@Override @Override
public long write( String path, ReadableByteChannel data, ByteBuffer temporaryBuffer, public long write( String path, ReadableByteChannel data, ByteBuffer temporaryBuffer,
boolean hasData, int recordSize ) throws IOException boolean hasData, int requiredElementAlignment ) throws IOException
{ {
char[] chars = path.toCharArray(); char[] chars = path.toCharArray();
targetBuffer.writeShort( chars.length ); targetBuffer.writeShort( chars.length );
Expand All @@ -56,7 +56,7 @@ public long write( String path, ReadableByteChannel data, ByteBuffer temporaryBu
long totalWritten = Short.BYTES + chars.length* Character.BYTES + Byte.BYTES; long totalWritten = Short.BYTES + chars.length* Character.BYTES + Byte.BYTES;
if ( hasData ) if ( hasData )
{ {
targetBuffer.writeInt( recordSize ); targetBuffer.writeInt( requiredElementAlignment );
totalWritten += Integer.BYTES; totalWritten += Integer.BYTES;
totalWritten += buffer.write( data ); totalWritten += buffer.write( data );
buffer.close(); buffer.close();
Expand Down

0 comments on commit b35370a

Please sign in to comment.