public IBTree LoadBTree(object id) { var oid = (OID)id; try { if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Debug(string.Format("LazyOdbBtreePersister: Loading btree with id {0}", oid)); } if (oid == StorageEngineConstant.NullObjectId) { throw new OdbRuntimeException( BTreeError.InvalidIdForBtree.AddParameter(StorageEngineConstant.NullObjectId)); } _tree = (IBTree)_engine.GetObjectFromOid(oid); _tree.SetId(oid); _tree.SetPersister(this); var root = _tree.GetRoot(); root.SetBTree(_tree); return(_tree); } catch (Exception e) { throw new OdbRuntimeException(BTreeError.InternalError, e); } }
// Commented by Olivier 05/11/2007 // persister.flush(); /// <summary> /// <pre>1 take median element /// 2 insert the median in the parent (shifting necessary elements) /// 3 create a new node with right part elements (moving keys and values and children) /// 4 set this new node as a child of parent</pre> /// </summary> public virtual void Split(IBTreeNode parent, IBTreeNode node2Split, int childIndex) { // BTreeValidator.validateNode(parent, parent == root); // BTreeValidator.validateNode(node2Split, false); // 1 var medianValue = node2Split.GetMedian(); // 2 parent.SetKeyAndValueAt(medianValue, childIndex, true, true); // 3 var rightPartTreeNode = node2Split.ExtractRightPart(); // 4 parent.SetChildAt(rightPartTreeNode, childIndex + 1); parent.SetChildAt(node2Split, childIndex); parent.IncrementNbChildren(); _persister.SaveNode(parent); _persister.SaveNode(rightPartTreeNode); _persister.SaveNode(node2Split); if (!OdbConfiguration.IsBTreeValidationEnabled()) { return; } BTreeValidator.ValidateNode(parent, parent == _root); BTreeValidator.ValidateNode(rightPartTreeNode, false); BTreeValidator.ValidateNode(node2Split, false); }
public virtual void Test4Sort() { var baseName = GetBaseName(); SetUp(baseName); var d = OdbConfiguration.GetIndexBTreeDegree(); try { OdbConfiguration.SetIndexBTreeDegree(40); var odb = Open(baseName); var aq = odb.Query <VO.Login.Function>(); (aq.Descend("name").Constrain("function 2").Equal()).Or( aq.Descend("name").Constrain("function 3").Equal()).Not(); aq.Descend("name").OrderDescending(); var l = aq.Execute <VO.Login.Function>(true, -1, -1); odb.Close(); AssertEquals(48, l.Count); var f = l.GetFirst(); AssertEquals("function 9", f.GetName()); } finally { OdbConfiguration.SetIndexBTreeDegree(d); } }
public System.Reflection.ConstructorInfo GetConstructorOf(System.String fullClassName) { System.Type clazz = classPool.GetClass(fullClassName); try { // Checks if exist a default constructor - with no parameters System.Reflection.ConstructorInfo constructor = clazz.GetConstructor(new System.Type[0]); return(constructor); } catch (System.MethodAccessException e) { // else take the constructer with the smaller number of parameters // and call it will null values // @TODO Put this inf oin cache ! if (OdbConfiguration.IsDebugEnabled(LogId)) { DLogger.Debug(clazz + " does not have default constructor! using a 'with parameter' constructor will null values"); } System.Reflection.ConstructorInfo[] constructors = clazz.GetConstructors(); int numberOfParameters = 1000; int bestConstructorIndex = 0; for (int i = 0; i < constructors.Length; i++) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.reflect.Constructor.getParameterTypes' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" if (constructors[i].GetParameters().Length < numberOfParameters) { bestConstructorIndex = i; } } System.Reflection.ConstructorInfo constructor = constructors[bestConstructorIndex]; return(constructor); } }
public InstanceBuilder(IStorageEngine engine) { this.triggerManager = OdbConfiguration.GetCoreProvider().GetLocalTriggerManager(engine); this.classIntrospector = OdbConfiguration.GetCoreProvider().GetClassIntrospector(); this.classPool = OdbConfiguration.GetCoreProvider().GetClassPool(); this.engine = engine; }
public static void test1() { //OdbConfiguration.SetDebugEnabled(true); OdbConfiguration.SetReconnectObjectsToSession(false); try { string file = "Test.NeoDatis"; IOUtil.DeleteFile(file); ODB odb = ODBFactory.Open(file); OID oid = odb.Store(new Function("f1")); odb.Close(); Console.WriteLine("Write Done!"); odb = ODBFactory.Open(file); Objects <Function> functions = odb.GetObjects <Function>(); Console.WriteLine(" Number of functions = " + functions.Count); Function f = (Function)odb.GetObjectFromId(oid); Console.WriteLine(f.ToString()); odb.Close(); } catch (Exception e) { Console.WriteLine(e); } Console.ReadLine(); }
public static void test4() { //OdbConfiguration.SetDebugEnabled(true); OdbConfiguration.SetReconnectObjectsToSession(false); try { int size = 1000; string file = "Test.NeoDatis"; Console.WriteLine("Oi"); IOUtil.DeleteFile(file); ODB odb = ODBFactory.Open(file); for (int i = 0; i < size; i++) { OID oid = odb.Store(new Function("function " + i)); } odb.Close(); odb = ODBFactory.Open(file); Objects <Function> functions = odb.GetObjects <Function>(new CriteriaQuery(Where.Equal("name", "function 199"))); Console.WriteLine(" Number of functions = " + functions.Count); odb.Close(); } catch (Exception e) { Console.WriteLine(e); } Console.ReadLine(); }
public long ReadOidPosition(OID oid) { if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Debug("ObjectReader: Start of readOidPosition for oid " + oid); } var blockNumber = StorageEngineConstant.GetIdBlockNumberOfOid(oid); var blockPosition = GetIdBlockPositionFromNumber(blockNumber); if (OdbConfiguration.IsLoggingEnabled()) { var blockNumberAsString = blockNumber.ToString(); var blockPositionAsString = blockPosition.ToString(); DLogger.Debug(string.Format("ObjectReader: Block number of oid {0} is ", oid) + blockNumberAsString + " / block position = " + blockPositionAsString); } var position = blockPosition + StorageEngineConstant.BlockIdOffsetForStartOfRepetition + ((oid.ObjectId - 1) % StorageEngineConstant.NbIdsPerBlock) * StorageEngineConstant.IdBlockRepetitionSize; if (OdbConfiguration.IsLoggingEnabled()) { var positionAsString = position.ToString(); DLogger.Debug(string.Format("ObjectReader: End of readOidPosition for oid {0} returning position ", oid) + positionAsString); } return(position); }
protected virtual void ManageFullCache() { if (OdbConfiguration.AutomaticallyIncreaseCacheSize()) { OdbConfiguration.SetMaxNumberOfObjectInCache((long)(OdbConfiguration .GetMaxNumberOfObjectInCache() * 1.2)); } }
/// <summary> /// Gets the real object position from its OID /// </summary> /// <param name="oid"> The oid of the object to get the position </param> /// <param name="useCache"> </param> /// <param name="throwException"> To indicate if an exception must be thrown if object is not found </param> /// <returns> The object position, if object has been marked as deleted then return StorageEngineConstant.DELETED_OBJECT_POSITION @ </returns> public long GetObjectPositionFromItsOid(OID oid, bool useCache, bool throwException) { if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Debug("ObjectReader: getObjectPositionFromItsId for oid " + oid); } // Check if oid is in cache var position = StorageEngineConstant.ObjectIsNotInCache; if (useCache) { // This return -1 if not in the cache position = _storageEngine.GetSession().GetCache().GetObjectPositionByOid(oid); } // FIXME Check if we need this. Removing it causes the TestDelete.test6 to fail if (position == StorageEngineConstant.DeletedObjectPosition) { if (throwException) { throw new CorruptedDatabaseException(NDatabaseError.ObjectIsMarkedAsDeletedForOid.AddParameter(oid)); } return(StorageEngineConstant.DeletedObjectPosition); } if (position != StorageEngineConstant.ObjectIsNotInCache && position != StorageEngineConstant.DeletedObjectPosition) { return(position); } // The position was not found is the cache position = ReadOidPosition(oid); position += StorageEngineConstant.BlockIdRepetitionIdStatus; _fsi.SetReadPosition(position); var idStatus = _fsi.ReadByte(); var objectPosition = _fsi.ReadLong(); if (!IDStatus.IsActive(idStatus)) { // if object position == 0, The object dos not exist if (throwException) { if (objectPosition == 0) { throw new CorruptedDatabaseException(NDatabaseError.ObjectWithOidDoesNotExist.AddParameter(oid)); } throw new CorruptedDatabaseException(NDatabaseError.ObjectIsMarkedAsDeletedForOid.AddParameter(oid)); } return(objectPosition == 0 ? StorageEngineConstant.ObjectDoesNotExist : StorageEngineConstant.DeletedObjectPosition); } if (OdbConfiguration.IsLoggingEnabled()) { var positionAsString = objectPosition.ToString(); DLogger.Debug("ObjectReader: object position of object with oid " + oid + " is " + positionAsString); } return(objectPosition); }
/// <summary> /// Read the class info header with the specific oid /// </summary> /// <returns> The read class info object @ </returns> public ClassInfo ReadClassInfoHeader(OID classInfoOid) { if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Debug("FileSystemReader: Reading new Class info Header with oid " + classInfoOid); } var classInfoPosition = GetObjectPositionFromItsOid(classInfoOid, true, true); _fsi.SetReadPosition(classInfoPosition); var blockSize = _fsi.ReadInt(); var blockType = _fsi.ReadByte(); if (!BlockTypes.IsClassHeader(blockType)) { throw new OdbRuntimeException( NDatabaseError.WrongTypeForBlockType.AddParameter("Class Header").AddParameter(blockType). AddParameter(classInfoPosition)); } //class info category, to remove _fsi.ReadByte(); var classInfoId = OIDFactory.BuildClassOID(_fsi.ReadLong()); var previousClassOID = ReadOid(); var nextClassOID = ReadOid(); var nbObjects = _fsi.ReadLong(); var originalZoneInfoFirst = ReadOid(); var originalZoneInfoLast = ReadOid(); var fullClassName = _fsi.ReadString(); var maxAttributeId = _fsi.ReadInt(); var attributesDefinitionPosition = _fsi.ReadLong(); var classInfo = new ClassInfo(fullClassName) { Position = classInfoPosition, ClassInfoId = classInfoId, PreviousClassOID = previousClassOID, NextClassOID = nextClassOID, MaxAttributeId = maxAttributeId, AttributesDefinitionPosition = attributesDefinitionPosition }; classInfo.OriginalZoneInfo.SetNbObjects(nbObjects); classInfo.OriginalZoneInfo.First = originalZoneInfoFirst; classInfo.OriginalZoneInfo.Last = originalZoneInfoLast; classInfo.CommitedZoneInfo.SetBasedOn(classInfo.OriginalZoneInfo); // FIXME Convert block size to long ?? var realBlockSize = (int)(_fsi.GetPosition() - classInfoPosition); if (blockSize != realBlockSize) { throw new OdbRuntimeException( NDatabaseError.WrongBlockSize.AddParameter(blockSize).AddParameter(realBlockSize).AddParameter( classInfoPosition)); } return(classInfo); }
/// <summary> /// Adds a write action to the transaction /// </summary> /// <param name="writeAction"> The write action to be added </param> /// <param name="persistWriteAction"> To indicate if write action must be persisted </param> private void AddWriteAction(WriteAction writeAction, bool persistWriteAction) { if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Info(string.Format("OdbTransaction: Adding WriteAction in Transaction of session {0}", _session.GetId())); } if (writeAction.IsEmpty()) { return; } CheckRollback(); if (!_hasBeenPersisted && persistWriteAction) { Persist(); } if (persistWriteAction) { writeAction.PersistMeTo(_fsi); } // Only adds the write action to the list if the transaction keeps all in // memory if (_hasAllWriteActionsInMemory) { _writeActions.Add(writeAction); } _numberOfWriteActions++; if (_hasAllWriteActionsInMemory && _numberOfWriteActions > StorageEngineConstant.MaxNumberOfWriteObjectPerTransaction) { _hasAllWriteActionsInMemory = false; foreach (var defaultWriteAction in _writeActions) { defaultWriteAction.Clear(); } _writeActions.Clear(); if (OdbConfiguration.IsLoggingEnabled()) { var numberOfWriteActions = _numberOfWriteActions.ToString(); var maxNumberOfWriteObjectPerTransactionAsString = StorageEngineConstant.MaxNumberOfWriteObjectPerTransaction.ToString(); DLogger.Info("OdbTransaction: Number of objects has exceeded the max number " + numberOfWriteActions + "/" + maxNumberOfWriteObjectPerTransactionAsString + ": switching to persistent transaction managment"); } } }
protected virtual void Init() { CheckRuntimeCompatibility(); isClosed = false; isLocal = baseIdentification.IsLocal(); // The check if it is a new Database must be executed before object // writer initialization. Because Object Writer Init // Creates the file so the check (which is based on the file existence // would always return false*/ bool isNewDatabase = IsNewDatabase(); commitListeners = new OdbArrayList <ICommitListener>(); classIntrospector = provider.GetClassIntrospector(); ISession session = BuildDefaultSession(); // Object Writer must be created before object Reader objectWriter = BuildObjectWriter(); // Object writer is a two Phase init object objectWriter.Init2(); objectReader = BuildObjectReader(); AddSession(session, false); // If the file does not exist, then a default header must be created if (isNewDatabase) { objectWriter.CreateEmptyDatabaseHeader(OdbTime.GetCurrentTimeInMs(), baseIdentification.GetUserName(), baseIdentification.GetPassword()); } else { try { GetObjectReader().ReadDatabaseHeader(baseIdentification.GetUserName(), baseIdentification.GetPassword()); } catch (ODBAuthenticationRuntimeException e) { Close(); throw; } } objectWriter.AfterInit(); objectIntrospector = BuildObjectIntrospector(); this.triggerManager = BuildTriggerManager(); // This forces the initialization of the meta model MetaModel metaModel = GetMetaModel(); if (OdbConfiguration.CheckModelCompatibility()) { CheckMetaModelCompatibility(classIntrospector.Instrospect(metaModel.GetAllClasses())); } // logically locks access to the file (only for this Virtual machine) FileMutex.GetInstance().OpenFile(GetStorageDeviceName()); // Updates the Transaction Id in the file objectWriter.WriteLastTransactionId(GetCurrentTransactionId()); this.objectWriter.SetTriggerManager(this.triggerManager); this.introspectionCallbackForInsert = new DefaultInstrumentationCallbackForStore(this, triggerManager, false); this.introspectionCallbackForUpdate = new DefaultInstrumentationCallbackForStore(this, triggerManager, true); }
private void Persist() { _nbPersist++; if (OdbConfiguration.IsLoggingEnabled()) { var count = _modifiedObjectOids.Count.ToString(); DLogger.Debug(string.Concat("LazyOdbBtreePersister: ", "persist ", _nbPersist.ToString(), " : Saving " + count + " objects - ", GetHashCode().ToString())); } var nbCommited = 0; var i = 0; var size = _modifiedObjectOids.Count; IEnumerator iterator = _modifiedObjectOidList.GetEnumerator(); while (iterator.MoveNext()) { var oid = (OID)iterator.Current; if (oid == null) { continue; } nbCommited++; long t0; long t1; try { t0 = OdbTime.GetCurrentTimeInMs(); var @object = _oids[oid]; _engine.Store(@object); t1 = OdbTime.GetCurrentTimeInMs(); } catch (Exception e) { throw new OdbRuntimeException( BTreeError.InternalError.AddParameter("Error while storing object with oid " + oid), e); } if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Debug(string.Concat("LazyOdbBtreePersister: ", "Committing oid " + oid, " | ", i.ToString(), "/", size.ToString(), " | ", (t1 - t0).ToString(), " ms")); } i++; } if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Debug(string.Concat("LazyOdbBtreePersister: ", nbCommited.ToString(), " commits / ", size.ToString())); } }
public void Check_changing_btree_degree() { Assert.That(OdbConfiguration.GetIndexBTreeDegree(), Is.EqualTo(OdbConfiguration.DefaultIndexBTreeDegree)); const int newIndexBTreeSize = 30; OdbConfiguration.SetIndexBTreeDegree(newIndexBTreeSize); Assert.That(OdbConfiguration.GetIndexBTreeDegree(), Is.EqualTo(newIndexBTreeSize)); }
public void Check_turning_on_the_logging() { Assert.That(OdbConfiguration.IsLoggingEnabled(), Is.False); OdbConfiguration.EnableLogging(); Assert.That(OdbConfiguration.IsLoggingEnabled(), Is.True); OdbConfiguration.DisableLogging(); Assert.That(OdbConfiguration.IsLoggingEnabled(), Is.False); }
public void Check_turning_on_the_btree_validation() { Assert.That(OdbConfiguration.IsBTreeValidationEnabled(), Is.False); OdbConfiguration.EnableBTreeValidation(); Assert.That(OdbConfiguration.IsBTreeValidationEnabled(), Is.True); OdbConfiguration.DisableBTreeValidation(); Assert.That(OdbConfiguration.IsBTreeValidationEnabled(), Is.False); }
/// <summary> </summary> /// <param name="s"> /// </param> /// <param name="withSize">if true, returns an array with an initial int with its size /// </param> /// <param name="totalSpace">The total space of the string (can be bigger that the real string size - to support later in place update) /// </param> /// <returns> The byte array that represent the string /// </returns> /// <throws> UnsupportedEncodingException </throws> public byte[] StringToByteArray(System.String s, bool withSize, int totalSpace, bool withEncoding) { byte[] bytes = null; if (withEncoding && hasEncoding) { try { bytes = Encoding.GetEncoding(ENCODING).GetBytes(s); } catch (Exception e) { throw new ODBRuntimeException(NeoDatisError.UnsupportedEncoding.AddParameter(encoding)); } } else { bytes = Encoding.ASCII.GetBytes(s); } if (!withSize) { return(bytes); } int totalSize = 0; if (totalSpace == -1) { // we always store a string with X the size to enable in place update for bigger string later totalSize = OdbConfiguration.GetStringSpaceReserveFactor() * bytes.Length + 2 * ODBType.NativeInt.GetSize(); } else { totalSize = totalSpace; } byte[] totalSizeBytes = IntToByteArray(totalSize); byte[] stringRealSize = IntToByteArray(bytes.Length); byte[] bytes2 = new byte[totalSize + IntSize_x_2]; for (int i = 0; i < 4; i++) { bytes2[i] = totalSizeBytes[i]; } for (int i = 4; i < 8; i++) { bytes2[i] = stringRealSize[i - 4]; } for (int i = 0; i < bytes.Length; i++) { bytes2[i + 8] = bytes[i]; } return(bytes2); }
/// <summary> /// Used to rebuild an index /// </summary> public void RebuildIndex(string className, string indexName) { if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Info(string.Format("StorageEngine: Rebuilding index {0} on class {1}", indexName, className)); } var classInfo = GetMetaModel().GetClassInfo(className, true); var classInfoIndex = GetClassInfoIndex(className, indexName, classInfo); DeleteIndex(className, indexName); AddIndexOn(className, indexName, classInfo.GetAttributeNames(classInfoIndex.AttributeIds), !classInfoIndex.IsUnique); }
public void Register_logger_and_check_logged_messages() { var logger = new FakeLogger(); OdbConfiguration.RegisterLogger(logger); DLogger.Info("info"); DLogger.Debug("debug"); DLogger.Warning("warning"); DLogger.Error("error"); Assert.That(logger.GetInfoMessage(), Is.EqualTo("info")); Assert.That(logger.GetDebugMessage(), Is.EqualTo("debug")); Assert.That(logger.GetWarningMessage(), Is.EqualTo("warning")); Assert.That(logger.GetErrorMessage(), Is.EqualTo("error")); }
private void UpdateMetaModel() { if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Info("StorageEngine: Automatic refactoring : updating meta model"); } var metaModel = GetMetaModel(); var storedClasses = metaModel.GetAllClasses().ToList(); foreach (var userClass in storedClasses) { _objectWriter.UpdateClassInfo(userClass, true); } }
static void Main() { XmlConfigurator.Configure(new FileInfo("log4net.xml")); const string dbName = "mydb.ndb"; OdbFactory.Delete(dbName); OdbConfiguration.RegisterLogger(new Log4NetLogger()); using (var odb = OdbFactory.Open(dbName)) { for (var i = 0; i < Count; i++) { odb.Store(new Warrior(string.Format("Warrior {0}", i + 1))); } } using (var odb = OdbFactory.OpenLast()) { var warriors = odb.Query <Warrior>().Execute <Warrior>().ToList(); for (var i = 0; i < Count; i++) { warriors[i].LeftHand = new Field(i + 3); warriors[i].RightHand = new Sword(i + 2); odb.Store(warriors[i]); } } using (var odb = OdbFactory.OpenLast()) { var warriors = odb.Query <Warrior>().Execute <Warrior>().ToList(); foreach (var warrior in warriors) { odb.Delete(warrior); } } using (var odb = OdbFactory.OpenLast()) { var finalCount = odb.Query <Warrior>().Execute <Warrior>().Count; Console.WriteLine("Final count: {0}", finalCount); } }
private void Persist() { CheckFileAccess(null); if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Debug(string.Format("OdbTransaction: # Persisting transaction {0}", GetName())); } _fsi.SetWritePosition(0, false); _fsi.WriteBoolean(_isCommited, false); _fsi.WriteLong(_creationDateTime, false); // Size _fsi.WriteLong(0, false); _hasBeenPersisted = true; }
public static void ValidateNode(IBTreeNode node, bool isRoot) { if (!OdbConfiguration.IsBTreeValidationEnabled()) { return; } ValidateNode(node); if (isRoot && node.HasParent()) { throw new BTreeNodeValidationException("Root node with a parent: " + node); } if (!isRoot && !node.HasParent()) { throw new BTreeNodeValidationException("Internal node without parent: " + node); } }
public void DeleteIndex(string className, string indexName) { var classInfo = GetMetaModel().GetClassInfo(className, true); var classInfoIndex = GetClassInfoIndex(className, indexName, classInfo); if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Info(string.Format("StorageEngine: Deleting index {0} on class {1}", indexName, className)); } Delete(classInfoIndex); classInfo.RemoveIndex(classInfoIndex); if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Info(string.Format("StorageEngine: Index {0} deleted", indexName)); } }
/// <summary> /// saves the bree node Only puts the current node in an 'modified Node' map to be saved on commit /// </summary> public void SaveNode(IBTreeNode node) { OID oid; // Here we only save the node if it does not have id, // else we just save into the hashmap if (node.GetId() == StorageEngineConstant.NullObjectId) { try { // first get the oid. : -2:it could be any value oid = _engine.GetObjectWriter().GetIdManager().GetNextObjectId(-2); node.SetId(oid); oid = _engine.Store(oid, node); if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Debug(string.Format("LazyOdbBtreePersister: Saved node id {0}", oid)); } // + " : " + // node.toString()); if (_tree != null && node.GetBTree() == null) { node.SetBTree(_tree); } _oids.Add(oid, node); return; } catch (Exception e) { throw new OdbRuntimeException(BTreeError.InternalError.AddParameter("While saving node"), e); } } oid = (OID)node.GetId(); _oids.Add(oid, node); AddModifiedOid(oid); }
public override void DefragmentTo(string newFileName) { var start = OdbTime.GetCurrentTimeInMs(); var totalNbObjects = 0L; var newStorageEngine = new StorageEngine(new FileIdentification(newFileName)); var j = 0; var criteriaQuery = new SodaQuery(typeof(object)); var defragObjects = GetObjects <object>(criteriaQuery, true, -1, -1); foreach (var defragObject in defragObjects) { newStorageEngine.Store(defragObject); totalNbObjects++; if (OdbConfiguration.IsLoggingEnabled()) { if (j % 10000 == 0) { DLogger.Info(string.Concat("\nStorageEngine: ", totalNbObjects.ToString(), " objects saved.")); } } j++; } newStorageEngine.Close(); var time = OdbTime.GetCurrentTimeInMs() - start; if (!OdbConfiguration.IsLoggingEnabled()) { return; } var nbObjectsAsString = totalNbObjects.ToString(); var timeAsString = time.ToString(); DLogger.Info(string.Format("StorageEngine: New storage {0} created with {1} objects in {2} ms.", newFileName, nbObjectsAsString, timeAsString)); }
public static void CheckDuplicateChildren(IBTreeNode node1, IBTreeNode node2) { if (!OdbConfiguration.IsBTreeValidationEnabled()) { return; } for (int i = 0; i < node1.GetNbChildren(); i++) { IBTreeNode child1 = node1.GetChildAt(i, true); for (int j = 0; j < node2.GetNbChildren(); j++) { if (child1 == node2.GetChildAt(j, true)) { throw new BTreeNodeValidationException("Duplicated node : " + child1); } } } }
/// <summary> /// Loads a node from its id. /// </summary> /// <remarks> /// Loads a node from its id. Tries to get if from memory, if not present then loads it from odb storage /// </remarks> /// <param name="id"> The id of the nod </param> /// <returns> The node with the specific id </returns> public IBTreeNode LoadNodeById(object id) { var oid = (OID)id; // Check if node is in memory var node = (IBTreeNode)_oids[oid]; if (node != null) { return(node); } // else load from odb try { if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Debug(string.Format("LazyOdbBtreePersister: Loading node with id {0}", oid)); } if (oid == null) { throw new OdbRuntimeException(BTreeError.InvalidIdForBtree.AddParameter("oid")); } var pn = (IBTreeNode)_engine.GetObjectFromOid(oid); pn.SetId(oid); if (_tree != null) { pn.SetBTree(_tree); } // Keep the node in memory _oids.Add(oid, pn); return(pn); } catch (Exception e) { throw new OdbRuntimeException(BTreeError.InternalError, e); } }
private static void CheckValuesOfChild(IKeyAndValue key, IBTreeNode node) { if (!OdbConfiguration.IsBTreeValidationEnabled()) { return; } if (node == null) { return; } for (int i = 0; i < node.GetNbKeys(); i++) { if (node.GetKeyAndValueAt(i).GetKey().CompareTo(key.GetKey()) >= 0) { throw new BTreeNodeValidationException("Left child with values bigger than pivot " + key + " : " + node); } } }