Dispose() public method

public Dispose ( ) : void
return void
Esempio n. 1
0
        public TextDeferredIndexer(DBreezeEngine engine)
        {
            this.DBreezeEngine = engine;
            LTrieSettings = new TrieSettings()
            {
                InternalTable = true
            };
            Storage = new StorageLayer(Path.Combine(engine.MainFolder, TableFileName), LTrieSettings, engine.Configuration);
            LTrie = new LTrie(Storage);
            LTrie.TableName = "DBreeze.TextIndexer";

            if (LTrie.Storage.Length > 100000)  //Recreating file if its size more then 100KB and it is empty
            {
                if (LTrie.Count(true) == 0)
                {
                    LTrie.Storage.RecreateFiles();
                    LTrie.Dispose();

                    Storage = new StorageLayer(Path.Combine(engine.MainFolder, TableFileName), LTrieSettings, engine.Configuration);
                    LTrie = new LTrie(Storage);
                    LTrie.TableName = "DBreeze.TextIndexer";
                }
            }

            if (LTrie.Count(true) > 0)
                this.StartDefferedIndexing();
        }
Esempio n. 2
0
        private void RestoreNotFinishedTransactions()
        {
            //TODO Trie settings from the table must be taken from schema (when they will differ)

            //STORE FILE NAME of rollback not table name
            try
            {
                byte[] btCommittedTablesNames =null;
                List<string> committedTablesNames = new List<string>();

                if (LTrie.Count(false) == 0)     //All ok
                {
                    LTrie.RemoveAll(true);
                    return;
                }

                string physicalPathToTheUserTable = String.Empty;

                //Settigns and storage for Committed tables !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   MUST BE TAKEN FROM SCHEMA, FOR NOW DEFAULT
                TrieSettings ltrSet = null;
                IStorage storage = null;
                DBreeze.LianaTrie.LTrie ltrie = null;

                foreach (var row in LTrie.IterateForward())
                {
                    btCommittedTablesNames = row.GetFullValue(true);

                    committedTablesNames = System.Text.Encoding.UTF8.GetString(btCommittedTablesNames).DeserializeXml<List<string>>();

                    foreach (var fn in committedTablesNames)
                    {
                        //Trying to get path from the Schema, there is universal function for getting table physical TABLE FULL PATH /NAME

                        physicalPathToTheUserTable = Engine.DBreezeSchema.GetPhysicalPathToTheUserTable(fn);

                        //Returned path can be empty, if no more such table
                        if (physicalPathToTheUserTable == String.Empty)
                            continue;

                        //We don't restore in-memory tables
                        if (physicalPathToTheUserTable == "MEMORY")
                            continue;

                        //we open ltrie, and it automatically restores rollback
                        ltrSet = new TrieSettings();     //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   MUST BE TAKEN FROM SCHEMA, FOR NOW DEFAULT
                        //storage = new TrieDiskStorage(physicalPathToTheUserTable, ltrSet, Engine.Configuration);
                        storage = new StorageLayer(physicalPathToTheUserTable, ltrSet, Engine.Configuration);
                        ltrie = new LTrie(storage);

                        //closing trie, that Schema could open it again
                        ltrie.Dispose();

                        ////Deleting rollback file for such table
                        //physicalPathToTheUserTable += ".rol";
                        //System.IO.File.Delete(physicalPathToTheUserTable);
                    }

                    committedTablesNames.Clear();
                }

                //If all ok, recreate file
                LTrie.RemoveAll(true);
            }
            catch (OperationCanceledException ex)
            {
                throw ex;
            }
            //catch (System.Threading.ThreadAbortException ex)
            //{
            //    //We don'T make DBisOperable = false;
            //    throw ex;
            //}
            catch (Exception ex)
            {
                //BRINGS TO DB NOT OPERATABLE
                this.Engine.DBisOperable = false;
                this.Engine.DBisOperableReason = "TransactionsCoordinator.RestoreNotFinishedTransaction";
                //NOT CASCADE ADD EXCEPTION
                throw DBreezeException.Throw(DBreezeException.eDBreezeExceptions.CLEAN_ROLLBACK_FILES_FOR_FINISHED_TRANSACTIONS_FAILED);
            }
        }
Esempio n. 3
0
        private void TestKrome()
        {
            using (var tran = engine.GetTransaction())
            {
                byte[] ptr = tran.InsertDataBlock("t1", null, new byte[] { 1, 2, 3 });

                tran.Insert<int, byte[]>("t1", 1, ptr);
                //NestedTable nt = tran.InsertTable<int>("t1", 1, 0);
                //nt.Insert<int, int>(1, 1);
                tran.Commit();
            }

            using (var tran = engine.GetTransaction())
            {
                var row = tran.Select<int,byte[]>("t1",1);
                byte[] val = row.Value;

                //NestedTable nt = tran.SelectTable<int>("t1", 1, 0);
                //var row = nt.Select<int, int>(1);

                tran.RemoveAllKeys("t1", true);

                byte[] res = tran.SelectDataBlock("t1", val);

                //Console.WriteLine("Key: {0}", row.Value);
            }
            return;

            //using (var tran = engine.GetTransaction())
            //{
            //    for (int i = 0; i < 1000000; i++)
            //    {
            //        tran.Insert<int, byte>("t1", i, 1);
            //    }

            //    tran.Commit();
            //}

            //Console.WriteLine("***");
            //byte bt = 1;

            //using (var tran = engine.GetTransaction())
            //{
            //    DBreeze.Diagnostic.SpeedStatistic.StartCounter("a");
            //    foreach (var row in tran.SelectForward<int, byte>("t1"))
            //    {
            //        bt = row.Value;
            //       // Console.WriteLine("Key: {0}", row.Key);
            //    }
            //    DBreeze.Diagnostic.SpeedStatistic.PrintOut("a",true);
            //}

            //return;

            using (var tran = engine.GetTransaction())
            {
                tran.Insert<int, byte>("t1", 1, 1);
                tran.Insert<int, byte>("t2", 1, 1);
                tran.Insert<int, byte>("t3", 1, 1);

                tran.Commit();
            }

            using (var tran = engine.GetTransaction())
            {
                tran.SynchronizeTables("t2");

                LTrieSettings = new TrieSettings();
                LTrieStorage = new StorageLayer(@"E:\temp\DBreezeTest\DBR1\90000000", LTrieSettings, new DBreezeConfiguration());

                LTrie = new LTrie(LTrieStorage);
                LTrie.Add(((int)2).To_4_bytes_array_BigEndian(), ((int)2).To_4_bytes_array_BigEndian());
                LTrie.Commit();
                LTrie.Dispose();

                var row = tran.Select<int, byte>("t2", 1);

                Console.WriteLine("K: {0}", row.Value);

                tran.RestoreTableFromTheOtherFile("t2", @"E:\temp\DBreezeTest\DBR1\90000000");

                //row = tran.Select<int, byte>("t2", 1);

                Console.WriteLine("K: {0}", row.Value);
            }

            using (var tran = engine.GetTransaction())
            {
                foreach (var row in tran.SelectBackward<int,int>("t2"))
                {
                    Console.WriteLine("Key: {0}", row.Key);
                }
            }
        }