예제 #1
0
        /* Higher level, fast operations */

        /// <summary>
        /// Applies a write commit to the disk
        /// </summary>
        /// <param name="commit"></param>
        public int ApplyWriteCommit(WriteCommit commit)
        {
            //Loop through and push each object
            int totalSize = 0;

            foreach (var obj in commit.commits)
            {
                //Serialize. Get length
                int len = obj.GetLength();
                totalSize += len;

                //Open buffer
                byte[] payload = new byte[len];

                //Serialize to this
                obj.SerializeTo(this, payload, 0);

                //Insert
                LowLevelUpsertObject(obj.objectId, commit.commitId, obj.groupId, commit.commitType, payload);
            }

            //Update name table if needed
            if (nameTableDirty)
            {
                UpdateNameTable();
            }

            //Update TOC
            UpdateToc();

            return(totalSize);
        }
        /// <summary>
        /// Writes a commit to the disk in a thread-safe manner
        /// </summary>
        /// <param name="commit"></param>
        /// <returns></returns>
        public Task <int> WriteCommitAsync(WriteCommit commit)
        {
            var cmd = new WriteCommitCommand(this, commit);

            controller.QueueCommand(cmd);
            return(cmd.GetTask());
        }
예제 #3
0
        static void Main(string[] args)
        {
            MultithreadedContentDatabaseController mt = new MultithreadedContentDatabaseController();

            //Delete
            if (File.Exists("E:\\test.db"))
            {
                File.Delete("E:\\test.db");
            }

            //Open
            var session = mt.GetDatabaseSession("E:\\test.db", 512);

            //Make items
            var    commit = new WriteCommit(747669614976172074, 0xAA);
            Random rand   = new Random();

            for (int i = 0; i < 2000; i++)
            {
                TestDataset ds = new TestDataset(i);
                ds.Randomize(rand);
                WriteCommitObject obj = new WriteCommitObject((ulong)i, 123456789);
                ds.WriteToObject(obj);
                commit.CommitObject(obj);
                datasets.Add(ds);
            }
            session.WriteCommitAsync(commit);

            //Count
            Console.WriteLine("Count: " + session.CountAllItemsAsync().GetAwaiter().GetResult());

            //Close
            session.CloseDatabaseAsync().GetAwaiter().GetResult();

            //Open
            mt      = new MultithreadedContentDatabaseController();
            session = mt.GetDatabaseSession("E:\\test.db", 512);

            //Load and validate
            var           r   = session.FindAllItemsAsync().GetAwaiter().GetResult();
            ValidationJar jar = new ValidationJar();

            for (int i = 0; i < datasets.Count; i++)
            {
                var des = r.results[i].Deserialize();
                datasets[i].Validate(des, jar);
            }

            Console.WriteLine($"Done. {jar.checked_ok} OK, {jar.checked_failed} failed");
            Console.ReadLine();
        }
 public WriteCommitCommand(MultithreadedContentDatabaseSession session, WriteCommit commit)
 {
     this.session = session;
     this.commit  = commit;
 }