You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2019/05/02 22:45:01 UTC

[GitHub] [accumulo] keith-turner commented on issue #816: Create a metadata mutation builder

keith-turner commented on issue #816: Create a metadata mutation builder
URL: https://github.com/apache/accumulo/issues/816#issuecomment-488858789
 
 
   To support easily writing to Zookeeper, root table, or the metadata table I have been experimenting with an interface like the following.   I am thinking ServerContext would provide an instance of this interface.
   
   ```java
   /**
    * An abstraction layer for mutating Accumulo's persistent metadata.  This metadata may be stored
    * in Zookeeper of Accumulo's own metadata table.
    */
   public interface MetadataMutator {
     /**
      * Select what we are going to mutate.  This may return a mutator for Zookeeper or the metadata
      * tables.
      */
     public interface Selector {
       TabletMutator tablet(TableId tableId, Text endRow);
       TabletMutator tablet(KeyExtent extent);
       GcMutator deletesFor(TableId tableId);
     }
     
     /**
      * Interface for changing a tablets persistent data.
      */
     public interface TabletMutator {
       public TabletMutator setPrevEndRow(Text per);
       public TabletMutator addFile(String path, DataFileValue dfv);
       public TabletMutator addFiles(Map<String, DataFileValue> files);
       public TabletMutator removeFile(String path);
       public TabletMutator removeFiles(Collection<String> paths);
       
       void mutate();
     }
     
     /**
      * Interface for adding and removing file delete markers used for garbage collection.
      */
     public interface GcMutator {
       public void insert(String path);
       public void insert(Collection<String> paths);
       public void remove(String path);
       public void remove(Collection<String> paths);
     }
     
     Selector mutating();
   }
   ```
   
   Using this interface I rewrote [replaceDatafiles()](https://github.com/apache/accumulo/blob/5e6e36446744d2d43c82ca2fc1b76ddff6f0e76c/server/base/src/main/java/org/apache/accumulo/server/util/MasterMetadataUtil.java#L207) that is used to update a tablets files after a major compaction.
   
   ```java
     public static void replaceDatafiles(ServerContext context, KeyExtent extent,
         Set<FileRef> datafilesToDelete, Set<FileRef> scanFiles, FileRef path, Long compactionId,
         DataFileValue size, String address, TServerInstance lastLocation, ZooLock zooLock,
         boolean insertDeleteFlags) {
   
       MetadataMutator meta = context.getMetadataMutator();
       
       if (insertDeleteFlags) {
         meta.mutating().deletesFor(extent.getTableId()).insert(datafilesToDelete);
       }
   
       TabletMutator tablet = meta.mutating().tablet(extent);
       
       tablet.removeFiles(datafilesToDelete);
       tablet.addScans(scanFiles);
       if (size.getNumEntries() > 0)
         tablet.addFile(path, size);
       
       if (compactionId != null)
         tablet.updateCompactionId(compactionId);
       
       TServerInstance self = getTServerInstance(address, zooLock);
       
       tablet.insertLastLocation(self);
       
       if (lastLocation != null && !lastLocation.equals(self))
         tablet.removeLastLocation(lastLocation);
       
       tablet.updateLock(zooLock);
       
       tablet.mutate();
       
     }
   ```
   
   I am not sure about the actual names, but I like this design because when using it there is no need to worry about zookeeper or mutations.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services