Пример #1
0
 /**
  * Open a copy of the map in read-only mode.
  *
  * @return the opened map
  */
 protected MVMap<K, V> openReadOnly() {
   MVMap<K, V> m = new MVMap<K, V>(keyType, valueType);
   m.readOnly = true;
   HashMap<String, String> config = New.hashMap();
   config.put("id", String.valueOf(id));
   config.put("createVersion", String.valueOf(createVersion));
   m.init(store, config);
   m.root = root;
   return m;
 }
Пример #2
0
 /**
  * Open an old version for the given map.
  *
  * @param version the version
  * @return the map
  */
 public MVMap<K, V> openVersion(long version) {
   if (readOnly) {
     throw DataUtils.newUnsupportedOperationException(
         "This map is read-only - need to call the method on the writable map");
   }
   DataUtils.checkArgument(
       version >= createVersion,
       "Unknown version {0}; this map was created in version is {1}",
       version,
       createVersion);
   Page newest = null;
   // need to copy because it can change
   Page r = root;
   if (version >= r.getVersion()
       && (version == store.getCurrentVersion()
           || r.getVersion() >= 0
           || version <= createVersion
           || store.getFile() == null)) {
     newest = r;
   } else {
     // find the newest page that has a getVersion() <= version
     int i = searchRoot(version);
     if (i < 0) {
       // not found
       if (i == -1) {
         // smaller than all in-memory versions
         return store.openMapVersion(version, id, this);
       }
       i = -i - 2;
     }
     newest = oldRoots.get(i);
   }
   MVMap<K, V> m = openReadOnly();
   m.root = newest;
   return m;
 }