Skip to content

Commit

Permalink
In the MS client methods for manipulating the metadata tree, serve back
Browse files Browse the repository at this point in the history
the write nonce of the affected entry to the caller.  For UGs, this
eliminates the need for revalidating a locally-created or
locally-updated file after the update but in the absence of other
updates (since the UG will already have
the most recent information anyway, there is no need to update unless
the write nonce changes after the update was issued).
  • Loading branch information
jcnelson committed Aug 28, 2014
1 parent f45dd43 commit 6193ca1
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 35 deletions.
2 changes: 1 addition & 1 deletion UG/consistency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@ int fs_entry_coordinate( struct fs_core* core, char const* fs_path, struct fs_en

// try to become the coordinator
uint64_t current_coordinator = 0;
rc = ms_client_coordinate( core->ms, &current_coordinator, &ent );
rc = ms_client_coordinate( core->ms, &current_coordinator, &fent->write_nonce, &ent );

if( rc != 0 ) {
// failed to contact the MS
Expand Down
4 changes: 2 additions & 2 deletions UG/fs/mkdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ int fs_entry_mkdir( struct fs_core* core, char const* path, mode_t mode, uint64_
fs_entry_to_md_entry( core, &data, child, parent_id, parent_name );
free( parent_name );

// make the directory on the MS, filling in the file ID into the child
err = ms_client_mkdir( core->ms, &child->file_id, &data );
// make the directory on the MS, filling in the file ID and write nonce into the child
err = ms_client_mkdir( core->ms, &child->file_id, &child->write_nonce, &data );

if( err != 0 ) {
errorf("ms_client_create(%s) rc = %d\n", path, err );
Expand Down
8 changes: 4 additions & 4 deletions UG/fs/open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ int fs_entry_mknod( struct fs_core* core, char const* path, mode_t mode, dev_t d
struct md_entry data;
fs_entry_to_md_entry( core, &data, child, parent_id, parent_name );

// create the child on the MS, obtaining its file ID
err = ms_client_create( core->ms, &child->file_id, &data );
// create the child on the MS, obtaining its file ID and write nonce
err = ms_client_create( core->ms, &child->file_id, &child->write_nonce, &data );

md_entry_free( &data );

Expand Down Expand Up @@ -487,8 +487,8 @@ struct fs_file_handle* fs_entry_open( struct fs_core* core, char const* _path, u
struct md_entry data;
fs_entry_to_md_entry( core, &data, child, parent_id, parent_name );

// create synchronously, obtaining the child's file ID
*err = ms_client_create( core->ms, &child->file_id, &data );
// create synchronously, obtaining the child's file ID and write_nonce
*err = ms_client_create( core->ms, &child->file_id, &child->write_nonce, &data );

if( *err != 0 ) {
errorf("ms_client_create(%s) rc = %d\n", _path, *err );
Expand Down
4 changes: 2 additions & 2 deletions UG/fs/rename.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ int fs_entry_versioned_rename( struct fs_core* core, char const* old_path, char
}
if( err == 0 ) {
// rename on the MS
err = ms_client_rename( core->ms, &old_ent, &new_ent );
err = ms_client_rename( core->ms, &fent_old->write_nonce, &old_ent, &new_ent );
if( err != 0 ) {
errorf("ms_client_rename(%s --> %s) rc = %d\n", old_ent.name, new_ent.name, err );
}
Expand All @@ -351,7 +351,7 @@ int fs_entry_versioned_rename( struct fs_core* core, char const* old_path, char
}
else {
// do the rename on the MS
err = ms_client_rename( core->ms, &old_ent, &new_ent );
err = ms_client_rename( core->ms, &fent_old->write_nonce, &old_ent, &new_ent );
if( err != 0 ) {
errorf("ms_client_rename(%s --> %s) rc = %d\n", old_ent.name, new_ent.name, err );
}
Expand Down
6 changes: 3 additions & 3 deletions UG/fs/stat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ int fs_entry_chown( struct fs_core* core, char const* path, uint64_t user, uint6
struct md_entry up;
fs_entry_to_md_entry( core, &up, fent, parent_id, parent_name );

int rc = ms_client_update( core->ms, &up );
int rc = ms_client_update( core->ms, &fent->write_nonce, &up );
if( rc != 0 ) {
errorf("ms_client_update(%s) rc = %d\n", path, rc );
}
Expand Down Expand Up @@ -556,7 +556,7 @@ int fs_entry_chmod( struct fs_core* core, char const* path, uint64_t user, uint6
struct md_entry up;
fs_entry_to_md_entry( core, &up, fent, parent_id, parent_name );

int rc = ms_client_update( core->ms, &up );
int rc = ms_client_update( core->ms, &fent->write_nonce, &up );
if( rc != 0 ) {
errorf("ms_client_update(%s) rc = %d\n", path, rc );
}
Expand Down Expand Up @@ -611,7 +611,7 @@ int fs_entry_utime( struct fs_core* core, char const* path, struct utimbuf* tb,
struct md_entry up;
fs_entry_to_md_entry( core, &up, fent, parent_id, parent_name );

int rc = ms_client_update( core->ms, &up );
int rc = ms_client_update( core->ms, &fent->write_nonce, &up );
if( rc != 0 ) {
errorf("ms_client_update(%s) rc = %d\n", path, rc );
}
Expand Down
2 changes: 1 addition & 1 deletion UG/fs/sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ int fs_entry_fsync_metadata( struct fs_core* core, struct fs_file_handle* fh, st

fs_entry_list_block_ids( sync_ctx->dirty_blocks, &affected_blocks, &num_affected_blocks );

rc = ms_client_update_write( core->ms, &sync_ctx->md_snapshot, affected_blocks, num_affected_blocks );
rc = ms_client_update_write( core->ms, &fh->fent->write_nonce, &sync_ctx->md_snapshot, affected_blocks, num_affected_blocks );

// free memory
if( affected_blocks != NULL ) {
Expand Down
2 changes: 1 addition & 1 deletion UG/fs/trunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static int fs_entry_reversion_file( struct fs_core* core, char const* fs_path, s
fs_entry_to_md_entry( core, &ent, fent, parent_id, parent_name );

// synchronously update
rc = ms_client_update( core->ms, &ent );
rc = ms_client_update( core->ms, &fent->write_nonce, &ent );

md_entry_free( &ent );

Expand Down
2 changes: 1 addition & 1 deletion UG/fs/write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ int fs_entry_remote_write( struct fs_core* core, char const* fs_path, uint64_t f

fs_entry_list_write_message_blocks( write_msg, &affected_blocks, &num_affected_blocks );

err = ms_client_update_write( core->ms, &data, affected_blocks, num_affected_blocks );
err = ms_client_update_write( core->ms, &fent->write_nonce, &data, affected_blocks, num_affected_blocks );

if( err != 0 ) {
errorf("%ms_client_update(%s) rc = %d\n", fs_path, err );
Expand Down
69 changes: 55 additions & 14 deletions libsyndicate/ms-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2808,7 +2808,7 @@ uint64_t ms_client_make_file_id() {


// create a file record on the MS, synchronously
int ms_client_create( struct ms_client* client, uint64_t* file_id_ret, struct md_entry* ent ) {
int ms_client_create( struct ms_client* client, uint64_t* file_id_ret, int64_t* write_nonce_ret, struct md_entry* ent ) {
ent->type = MD_ENTRY_FILE;

uint64_t file_id = ms_client_make_file_id();
Expand All @@ -2827,10 +2827,13 @@ int ms_client_create( struct ms_client* client, uint64_t* file_id_ret, struct md
int rc = ms_client_file_post( client, &up, &reply );

if( rc == 0 ) {
// did we get back a file_id?
// did we get back a file_id and write_nonce?
if( reply.listing().entries_size() > 0 ) {

*file_id_ret = reply.listing().entries(0).file_id();
dbprintf("output file_id: %" PRIX64 "\n", *file_id_ret );
*write_nonce_ret = reply.listing().entries(0).write_nonce();

dbprintf("output file_id: %" PRIX64 " write_nonce: %" PRId64 "\n", *file_id_ret, *write_nonce_ret );
}
else {
rc = -ENODATA;
Expand All @@ -2844,7 +2847,7 @@ int ms_client_create( struct ms_client* client, uint64_t* file_id_ret, struct md


// make a directory on the MS, synchronously
int ms_client_mkdir( struct ms_client* client, uint64_t* file_id_ret, struct md_entry* ent ) {
int ms_client_mkdir( struct ms_client* client, uint64_t* file_id_ret, int64_t* write_nonce_ret, struct md_entry* ent ) {
ent->type = MD_ENTRY_DIR;

uint64_t file_id = ms_client_make_file_id();
Expand All @@ -2867,10 +2870,13 @@ int ms_client_mkdir( struct ms_client* client, uint64_t* file_id_ret, struct md_
int rc = ms_client_file_post( client, &up, &reply );

if( rc == 0 ) {
// did we get back a file_id?
// did we get back a file_id and write_nonce?
if( reply.listing().entries_size() > 0 ) {

*file_id_ret = reply.listing().entries(0).file_id();
dbprintf("output file_id: %" PRIX64 "\n", *file_id_ret );
*write_nonce_ret = reply.listing().entries(0).write_nonce();

dbprintf("output file_id: %" PRIX64 " write_nonce: %" PRId64 "\n", *file_id_ret, *write_nonce_ret );
}
else {
rc = -ENODATA;
Expand All @@ -2893,7 +2899,7 @@ int ms_client_delete( struct ms_client* client, struct md_entry* ent ) {
}

// update a record on the MS, synchronously, due to a write()
int ms_client_update_write( struct ms_client* client, struct md_entry* ent, uint64_t* in_affected_blocks, size_t num_affected_blocks ) {
int ms_client_update_write( struct ms_client* client, int64_t* write_nonce_ret, struct md_entry* ent, uint64_t* in_affected_blocks, size_t num_affected_blocks ) {

// generate our update
struct md_update up;
Expand All @@ -2912,7 +2918,22 @@ int ms_client_update_write( struct ms_client* client, struct md_entry* ent, uint

up.num_affected_blocks = num_affected_blocks;

int rc = ms_client_file_post( client, &up, NULL );
ms::ms_reply reply;

int rc = ms_client_file_post( client, &up, &reply );

if( rc == 0 ) {
// did we get back a write_nonce?
if( reply.listing().entries_size() > 0 ) {

*write_nonce_ret = reply.listing().entries(0).write_nonce();

dbprintf("updated write_nonce: %" PRId64 "\n", *write_nonce_ret );
}
else {
rc = -ENODATA;
}
}

// clean up
if( affected_blocks != NULL ) {
Expand All @@ -2925,12 +2946,12 @@ int ms_client_update_write( struct ms_client* client, struct md_entry* ent, uint
}

// update a record on the MS, synchronously, NOT due to a write()
int ms_client_update( struct ms_client* client, struct md_entry* ent ) {
return ms_client_update_write( client, ent, NULL, 0 );
int ms_client_update( struct ms_client* client, int64_t* write_nonce_ret, struct md_entry* ent ) {
return ms_client_update_write( client, write_nonce_ret, ent, NULL, 0 );
}

// change coordinator ownership of a file on the MS, synchronously
int ms_client_coordinate( struct ms_client* client, uint64_t* new_coordinator, struct md_entry* ent ) {
int ms_client_coordinate( struct ms_client* client, uint64_t* new_coordinator, int64_t* write_nonce, struct md_entry* ent ) {

// generate our update
struct md_update up;
Expand All @@ -2944,8 +2965,11 @@ int ms_client_coordinate( struct ms_client* client, uint64_t* new_coordinator, s
if( rc == 0 ) {
// got back a coordinator?
if( reply.listing().entries_size() > 0 ) {

*new_coordinator = reply.listing().entries(0).coordinator();
dbprintf("New coordinator of %" PRIX64 " is %" PRIu64 "\n", ent->file_id, *new_coordinator );
*write_nonce = reply.listing().entries(0).write_nonce();

dbprintf("New coordinator of %" PRIX64 " is %" PRIu64 ", write_nonce = %" PRId64 "\n", ent->file_id, *new_coordinator, *write_nonce );
}
else {
rc = -ENODATA;
Expand All @@ -2956,7 +2980,7 @@ int ms_client_coordinate( struct ms_client* client, uint64_t* new_coordinator, s
}

// rename from src to dest
int ms_client_rename( struct ms_client* client, struct md_entry* src, struct md_entry* dest ) {
int ms_client_rename( struct ms_client* client, int64_t* write_nonce, struct md_entry* src, struct md_entry* dest ) {
if( src->volume != dest->volume )
return -EXDEV;

Expand All @@ -2967,8 +2991,25 @@ int ms_client_rename( struct ms_client* client, struct md_entry* src, struct md_
struct md_update up;
ms_client_populate_update( &up, ms::ms_update::RENAME, 0, src );
memcpy( &up.dest, dest, sizeof(struct md_entry) );

ms::ms_reply reply;

return ms_client_file_post( client, &up, NULL );
int rc = ms_client_file_post( client, &up, &reply );

if( rc == 0 ) {
// got back a write nonce??
if( reply.listing().entries_size() > 0 ) {

*write_nonce = reply.listing().entries(0).write_nonce();

dbprintf("New write_nonce of %" PRIx64 " is %" PRId64 "\n", src->file_id, *write_nonce );
}
else {
rc = -ENODATA;
}
}

return rc;
}

// send a batch of updates.
Expand Down
12 changes: 6 additions & 6 deletions libsyndicate/ms-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,13 @@ int ms_client_view_unlock2( struct ms_client* client, char const* from_str, int

// file metadata API
uint64_t ms_client_make_file_id();
int ms_client_create( struct ms_client* client, uint64_t* file_id, struct md_entry* ent );
int ms_client_mkdir( struct ms_client* client, uint64_t* file_id, struct md_entry* ent );
int ms_client_create( struct ms_client* client, uint64_t* file_id, int64_t* write_nonce, struct md_entry* ent );
int ms_client_mkdir( struct ms_client* client, uint64_t* file_id, int64_t* write_nonce, struct md_entry* ent );
int ms_client_delete( struct ms_client* client, struct md_entry* ent );
int ms_client_update_write( struct ms_client* client, struct md_entry* ent, uint64_t* affected_blocks, size_t num_affected_blocks );
int ms_client_update( struct ms_client* client, struct md_entry* ent );
int ms_client_coordinate( struct ms_client* client, uint64_t* new_coordinator, struct md_entry* ent );
int ms_client_rename( struct ms_client* client, struct md_entry* src, struct md_entry* dest );
int ms_client_update_write( struct ms_client* client, int64_t* write_nonce, struct md_entry* ent, uint64_t* affected_blocks, size_t num_affected_blocks );
int ms_client_update( struct ms_client* client, int64_t* write_nonce, struct md_entry* ent );
int ms_client_coordinate( struct ms_client* client, uint64_t* new_coordinator, int64_t* write_nonce, struct md_entry* ent );
int ms_client_rename( struct ms_client* client, int64_t* write_nonce, struct md_entry* src, struct md_entry* dest );

// xattr API
int ms_client_getxattr( struct ms_client* client, uint64_t volume_id, uint64_t file_id, char const* xattr_name, char** xattr_value, size_t* xattr_value_len );
Expand Down

0 comments on commit 6193ca1

Please sign in to comment.