ivakegg commented on code in PR #3142:
URL: https://github.com/apache/accumulo/pull/3142#discussion_r1081352463


##########
server/base/src/main/java/org/apache/accumulo/server/util/ManagerMetadataUtil.java:
##########
@@ -256,4 +247,64 @@ public static Optional<StoredTabletFile> 
updateTabletDataFile(ServerContext cont
     tablet.mutate();
     return newFile;
   }
+
+  /**
+   * Update the last location if the location mode is "assignment". This will 
delete the previous
+   * last location if needed and set the new last location
+   *
+   * @param context The server context
+   * @param ample The metadata persistence layer
+   * @param tabletMutator The mutator being built
+   * @param extent The tablet extent
+   * @param location The new location
+   */
+  public static void updateLastForAssignmentMode(ClientContext context, Ample 
ample,
+      Ample.TabletMutator tabletMutator, KeyExtent extent, TServerInstance 
location) {
+    // if the location mode is assignment, then preserve the current location 
in the last
+    // location value
+    if 
("assignment".equals(context.getConfiguration().get(Property.TSERV_LAST_LOCATION_MODE)))
 {
+      TabletMetadata lastMetadata = ample.readTablet(extent, 
TabletMetadata.ColumnType.LAST);
+      TServerInstance lastLocation = (lastMetadata == null ? null : 
lastMetadata.getLast());
+      ManagerMetadataUtil.updateLast(tabletMutator, lastLocation, location);
+    }
+  }
+
+  /**
+   * Update the last location if the location mode is "compaction". This will 
delete the previous
+   * last location if needed and set the new last location
+   *
+   * @param context The server context
+   * @param tabletMutator The mutator being built
+   * @param lastLocation The last location
+   * @param address The server address
+   * @param zooLock The zookeeper lock
+   */
+  public static void updateLastForCompactionMode(ClientContext context, 
TabletMutator tabletMutator,
+      TServerInstance lastLocation, String address, ServiceLock zooLock) {
+    // if the location mode is 'compaction', then preserve the current 
compaction location in the
+    // last location value
+    if 
("compaction".equals(context.getConfiguration().get(Property.TSERV_LAST_LOCATION_MODE)))
 {
+      TServerInstance newLocation = getTServerInstance(address, zooLock);
+      updateLast(tabletMutator, lastLocation, newLocation);
+    }
+  }
+
+  /**
+   * Update the last location, deleting the previous location if needed
+   *
+   * @param tabletMutator The mutator being built
+   * @param lastLocation The last location (may be null)
+   * @param newLocation The new location
+   */
+  public static void updateLast(TabletMutator tabletMutator, TServerInstance 
lastLocation,
+      TServerInstance newLocation) {
+    if (lastLocation != null) {
+      if (!lastLocation.equals(newLocation)) {
+        tabletMutator.deleteLocation(lastLocation, LocationType.LAST);
+        tabletMutator.putLocation(newLocation, LocationType.LAST);
+      }
+    } else {
+      tabletMutator.putLocation(newLocation, LocationType.LAST);
+    }

Review Comment:
   But I did not want to "putLocation" if the lastLocation is equal to the 
newLocation.  This suggestion is too simple.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to