1 8 package org.ozoneDB.core.storage.gammaStore; 9 10 import java.io.IOException ; 11 import java.util.HashMap ; 12 import java.util.Iterator ; 13 import java.util.Map ; 14 import java.util.Properties ; 15 import java.util.logging.Level ; 16 import java.util.logging.Logger ; 17 import org.ozoneDB.ObjectNotFoundException; 18 import org.ozoneDB.OzoneCompatible; 19 import org.ozoneDB.PermissionDeniedException; 20 import org.ozoneDB.DxLib.DxBag; 21 import org.ozoneDB.DxLib.DxHashSet; 22 import org.ozoneDB.DxLib.DxIterator; 23 import org.ozoneDB.DxLib.DxSet; 24 import org.ozoneDB.core.Env; 25 import org.ozoneDB.core.GarbageCollector; 26 import org.ozoneDB.core.ObjectContainer; 27 import org.ozoneDB.core.ObjectID; 28 import org.ozoneDB.core.Permissions; 29 import org.ozoneDB.core.ServerComponent; 30 import org.ozoneDB.core.StoreManager; 31 import org.ozoneDB.core.Transaction; 32 import org.ozoneDB.core.User; 33 import org.ozoneDB.core.storage.Cache; 34 import org.ozoneDB.core.storage.PropertyConfigurableFactory; 35 import org.ozoneDB.core.storage.PropertyInfo; 36 37 38 42 public class GammaStore extends ServerComponent implements StoreManager { 43 44 private static final Logger log = Logger.getLogger(GammaStore.class.getName()); 45 46 public static final String OZONE_BASE = "org.ozoneDB"; 48 49 public static final String GAMMASTORE_BASE = OZONE_BASE + ".core.gammaStore"; 50 51 public static final PropertyInfo DIRECTORY = new PropertyInfo( 52 ".directory", 53 "String (path)", 54 null, 55 "main database directory, must be an absolute path", 56 new String [] { 57 "/var/ozone (*nix absolute path)", 58 "c:\\ozoneFiles (windows absolute path)", 59 } 60 ); 61 62 public static final PropertyInfo TXSTORAGEFACTORY = new PropertyInfo( 63 ".txStorageFactory", 64 "String (path)", 65 null, 66 "main database directory, must be an absolute path", 67 new String [] { 68 "/var/ozone/tx (*nix absolute path)", 69 "c:\\ozoneFiles\\tx (windows absolute path)", 70 } 71 ); 72 73 private static final String PROP_STORAGEFACTORY = ".storageFactory"; 74 75 private static final String PROP_NUMCONFIGS = ".numConfigs"; 76 77 private static final String PROP_STREAMFACTORY = ".streamFactory"; 78 79 private static final String PROP_CONTAINERCACHE = GAMMASTORE_BASE + ".containerCache"; 80 81 private StorageFactory[] storageFactories; 82 83 private StreamFactory[] streamFactories; 84 85 private Cache containerCache; 86 87 private IndexManager indexManager; 88 89 private Properties properties; 90 91 private Map containerNames = new HashMap (); 92 93 99 private GarbageCollector garbageCollector; 100 101 private StorageFactory txStorageFactory; 102 103 117 public GammaStore(Properties properties) { 118 super(Env.currentEnv()); 120 int numConfigs = Integer.parseInt(properties.getProperty(PROP_NUMCONFIGS, "1")); 121 if (numConfigs != 1) { 122 throw new RuntimeException ("currently only 1 config supported"); 123 } 124 125 setContainerCache((Cache) PropertyConfigurableFactory.create(Cache.class, properties, PROP_CONTAINERCACHE)); 127 128 storageFactories = new StorageFactory[numConfigs]; 130 streamFactories = new StreamFactory[numConfigs]; 131 for (int i = 0; i < numConfigs; i++) { 132 String prop = GAMMASTORE_BASE + "." + i + PROP_STORAGEFACTORY; 133 storageFactories[i] = (StorageFactory) PropertyConfigurableFactory.create(StorageFactory.class, properties, prop); 134 } 137 txStorageFactory = (StorageFactory) PropertyConfigurableFactory.create(StorageFactory.class, properties, GAMMASTORE_BASE + TXSTORAGEFACTORY.getKey()); 138 139 this.properties = properties; 140 } 141 142 public GammaStore(Env env) { 143 this(env.config); 144 } 145 146 public Cache getContainerCache() { 148 return containerCache; 149 } 150 151 public void setContainerCache(Cache containerCache) { 153 this.containerCache = containerCache; 154 } 155 156 private void abortObjectId(ObjectID objectId) { 157 } 161 162 163 public void abortTransaction(Transaction ta) throws IOException , ClassNotFoundException { 164 GammaTransaction transaction = (GammaTransaction) ta; 165 for (Iterator i = transaction.getContainerCache().copyToMap().values().iterator(); i.hasNext(); ) { 166 GammaContainer gammaContainer = (GammaContainer) i.next(); 167 abortObjectId(gammaContainer.getObjectId()); 168 } 169 transaction.getLogStorage().close(); 170 } 176 177 182 public DxBag clusterOfID(ObjectID id) throws Exception { 183 return null; 184 } 185 186 public void commitTransaction(Transaction ta) throws IOException , ClassNotFoundException { 187 } 188 189 public ObjectContainer containerForID(Transaction ta, ObjectID id) throws ObjectNotFoundException, IOException , ClassNotFoundException { 190 GammaContainer result = (GammaContainer) containerCache.get(id); 191 if (result == null) { 192 } 194 return result; 195 } 196 197 202 public ObjectContainer containerForName(Transaction ta, String name) throws Exception { 203 return null; 204 } 205 206 210 public void init(Env env) { 211 setGarbageCollector(env.getGarbageCollector()); 212 } 213 214 219 public void nameContainer(Transaction ta, ObjectContainer container, String name) throws PermissionDeniedException { 220 221 } 222 223 239 public ObjectContainer newContainerAndLock(Transaction ta, OzoneCompatible target, ObjectID objectId, Permissions permissions, int lockLevel) throws Exception { 240 GammaContainer result = new GammaContainer(objectId, this); 241 getContainerCache().put(objectId, result); 242 243 if (target != null) { 244 result.setTarget(target); 245 } 246 247 if (log.isLoggable(Level.FINEST)) log.finest("created new container " + result); 248 getGarbageCollector().notifyNewObjectContainer(result); 249 GammaTransaction gammaTransaction = (GammaTransaction) ta; 250 251 gammaTransaction.getContainerCache().put(result.getObjectId(), result); 252 253 return result; 254 } 255 256 public Object newTransactionData() { 257 return null; 259 } 260 261 public DxIterator objectIDIterator() { 262 return null; 265 } 266 267 271 public DxSet objectNames(Transaction ta) { 272 DxSet result = new DxHashSet(); 273 for(Iterator i = getContainerNames().entrySet().iterator(); i.hasNext(); ) { 274 result.add(i.next()); 275 } 276 return result; 277 } 278 279 292 public void prepareCommitTransaction(Transaction ta) throws IOException , ClassNotFoundException { 293 } 294 295 298 public void reportNamedObjectsToGarbageCollector() { 299 } 300 301 public void shutdown() throws Exception { 302 } 303 304 public void startup() throws Exception { 305 indexManager = new IndexManager(properties, "org.ozoneDB.core.gammaStore.IndexManager", true); 306 } 307 308 312 public void updateLockLevel(Transaction ta, ObjectContainer container) throws IOException { 313 if (log.isLoggable(Level.FINEST)) log.finest("updateLockLevel()"); 314 GammaContainer gammaContainer = (GammaContainer) container; 315 getContainerCache().put(gammaContainer.getObjectId(), gammaContainer); 316 } 317 318 public Transaction createTransaction(Env env, User user) { 319 return new GammaTransaction(this, getTxStorageFactory(), env, user); 320 } 321 322 private StorageFactory getTxStorageFactory() { 323 return txStorageFactory; 324 } 325 326 private Map getContainerNames() { 328 return containerNames; 329 } 330 331 private GarbageCollector getGarbageCollector() { 333 return garbageCollector; 334 } 335 336 private void setGarbageCollector(GarbageCollector garbageCollector) { 338 this.garbageCollector = garbageCollector; 339 } 340 341 public void save() throws Exception { 342 } 343 344 } 345 | Popular Tags |