@@ -109,6 +109,7 @@ static uint64_t gEndangeredChunksMaxCapacity;
109109static uint64_t gDisconnectedCounter = 0 ;
110110inline LinearAssignmentCache gLinearAssignmentCache ;
111111inline bool gUseLinearAssignmentOptimizer ;
112+ static bool gUseChunkserverSideChunkLock ;
112113bool gAvoidSameIpChunkservers = false ;
113114
114115struct ChunkPart {
@@ -1180,10 +1181,11 @@ int chunk_get_partstomodify(uint64_t chunkid, int &recover, int &remove) {
11801181
11811182// Chunk operations
11821183
1183- // / @brief Performs the chunk creation operation, which consists of creating a new chunk with
1184+ // / @brief Performs the chunk creation operation, which consists of creating a new chunk with
11841185// / version 1, associating it with the given goal and sending create chunk messages to the provided
11851186// / chunkservers. The parts in the chunk are marked as being written (it is expecteted that client
1186- // / starts writing) if the corresponding chunkserver supports locking and the create chunk message was sent with locking.
1187+ // / starts writing) if the corresponding chunkserver supports locking and the create chunk message
1188+ // / was sent with locking.
11871189// / @param createdChunk A reference to a pointer where the created chunk will be stored.
11881190// / @param goal The goal that will be associated with the created chunk.
11891191// / @param serversWithChunkTypes The list of chunkservers to create the chunk on.
@@ -1201,7 +1203,8 @@ void chunk_create_operation(
12011203 server_with_type.second ));
12021204 bool sentChunkLock = false ;
12031205 matocsserv_send_createchunk (server_with_type.first , createdChunk->chunkid ,
1204- server_with_type.second , createdChunk->version , sentChunkLock);
1206+ server_with_type.second , createdChunk->version ,
1207+ gUseChunkserverSideChunkLock , sentChunkLock);
12051208
12061209 if (sentChunkLock) { createdChunk->parts .back ().mark_being_written (); }
12071210 // If the chunk lock was not sent, it means that the chunkserver does not support locking,
@@ -1225,14 +1228,14 @@ void chunk_increase_version_operation(Chunk *chunk, bool needsLocking) {
12251228 part.version = chunk->version + 1 ;
12261229 // If part is already being written then we don't need to ask the chunkserver to lock
12271230 // it again, and we can just increase the version.
1228- bool partNeedsLocking = !part.is_being_written () && needsLocking;
1231+ bool partNeedsLocking =
1232+ !part.is_being_written () && needsLocking && gUseChunkserverSideChunkLock ;
12291233 bool sentChunkLock = false ;
12301234 matocsserv_send_setchunkversion (part.server (), chunk->chunkid , chunk->version + 1 ,
1231- chunk->version , part.type , partNeedsLocking, sentChunkLock);
1235+ chunk->version , part.type , partNeedsLocking,
1236+ sentChunkLock);
12321237
1233- if (partNeedsLocking && sentChunkLock) {
1234- part.mark_being_written ();
1235- }
1238+ if (partNeedsLocking && sentChunkLock) { part.mark_being_written (); }
12361239 }
12371240 }
12381241
@@ -1248,18 +1251,20 @@ void chunk_increase_version_operation(Chunk *chunk, bool needsLocking) {
12481251void chunk_lock_operation (Chunk *chunk) {
12491252 bool mustWaitForReply = false ;
12501253 assert (chunk->isWritable ());
1251- for (auto &part : chunk->parts ) {
1252- if (part.is_valid ()) {
1253- if (part.is_busy ()) { continue ; }
1254- // No busy parts from now on
1255-
1256- bool sentChunkLock = false ;
1257- matocsserv_send_chunklock (part.server (), chunk->chunkid , part.type ,
1258- !part.is_being_written (), sentChunkLock);
1259- if (sentChunkLock) {
1260- part.mark_being_written ();
1261- mustWaitForReply = true ;
1262- part.mark_busy ();
1254+ if (gUseChunkserverSideChunkLock ) {
1255+ for (auto &part : chunk->parts ) {
1256+ if (part.is_valid ()) {
1257+ if (part.is_busy ()) { continue ; }
1258+ // No busy parts from now on
1259+
1260+ bool sentChunkLock = false ;
1261+ matocsserv_send_chunklock (part.server (), chunk->chunkid , part.type ,
1262+ !part.is_being_written (), sentChunkLock);
1263+ if (sentChunkLock) {
1264+ part.mark_being_written ();
1265+ mustWaitForReply = true ;
1266+ part.mark_busy ();
1267+ }
12631268 }
12641269 }
12651270 }
@@ -1298,7 +1303,8 @@ void chunk_duplicate_operation(Chunk *originalChunk, uint8_t goal, Chunk *&newCh
12981303 bool sentChunkLock = false ;
12991304 matocsserv_send_duplicatechunk (oldPart.server (), newChunk->chunkid , newChunk->version ,
13001305 oldPart.type , originalChunk->chunkid ,
1301- originalChunk->version , sentChunkLock);
1306+ originalChunk->version , gUseChunkserverSideChunkLock ,
1307+ sentChunkLock);
13021308
13031309 if (sentChunkLock) { newChunk->parts .back ().mark_being_written (); }
13041310 }
@@ -3173,6 +3179,7 @@ void chunk_reload(void) {
31733179 gAvoidSameIpChunkservers = cfg_getuint32 (" AVOID_SAME_IP_CHUNKSERVERS" , 0 );
31743180 gRedundancyLevel = cfg_getuint32 (" REDUNDANCY_LEVEL" , 0 );
31753181 gUseLinearAssignmentOptimizer = cfg_getuint32 (" USE_LINEAR_ASSIGNMENT_OPTIMIZER" , 1 );
3182+ gUseChunkserverSideChunkLock = cfg_getuint32 (" USE_CHUNKSERVER_SIDE_CHUNK_LOCK" , 0 );
31763183
31773184 uint32_t disableChunksDel = cfg_getuint32 (" DISABLE_CHUNKS_DEL" , 0 );
31783185 if (disableChunksDel) {
@@ -3268,6 +3275,7 @@ int chunk_strinit(void) {
32683275 gAvoidSameIpChunkservers = cfg_getuint32 (" AVOID_SAME_IP_CHUNKSERVERS" , 0 );
32693276 gRedundancyLevel = cfg_getuint32 (" REDUNDANCY_LEVEL" , 0 );
32703277 gUseLinearAssignmentOptimizer = cfg_getuint32 (" USE_LINEAR_ASSIGNMENT_OPTIMIZER" , 1 );
3278+ gUseChunkserverSideChunkLock = cfg_getuint32 (" USE_CHUNKSERVER_SIDE_CHUNK_LOCK" , 0 );
32713279
32723280 if (disableChunksDel) {
32733281 MaxDelHardLimit = MaxDelSoftLimit = 0 ;
0 commit comments