private void GetGameFolder()
    {
        GUILayout.Space(5);

        if (_database != null)
        {
            GUILayout.Label($"Database loaded: {_database.Tables.Length} tables.");
        }

        GUILayout.Label("Res Folder");

        GUILayout.BeginHorizontal();

        GameFolder = EditorGUILayout.TextField(GameFolder);

        if (GUILayout.Button("Submit"))
        {
            ResDir = GameFolder;

            if (_database == null || _database.Tables.Length == default)
            {
                _database = new FdbDatabase(new FdbFile($"{Path.Combine(ResDir, "./cdclient.fdb")}"));
            }
        }

        if (_database != null)
        {
            Database = _database;
        }

        GUILayout.EndHorizontal();
    }
Esempio n. 2
0
 private async Task NewDatabaseAsync()
 {
     using (FdbDatabase db = await OpenDatabaseAsync())
     {
         await db.ClearRangeAsync(db.GlobalSpace);
     }
 }
Esempio n. 3
0
 private async Task <PerformanceRecord> ReadParallelAsync(string operation, IEnumerable <uint> ids,
                                                          PerfTracker perfTracker,
                                                          int numberOfThreads)
 {
     using (FdbDatabase db = await OpenDatabaseAsync())
     {
         return(ExecuteReadWithParallel(operation, ids, numberOfThreads,
                                        () => ReadInternal(ids, perfTracker, db)));
     }
 }
Esempio n. 4
0
        private async Task <List <PerformanceRecord> > WriteAsync(string operation, IEnumerable <TestData> data,
                                                                  int itemsPerTransaction,
                                                                  int numberOfTransactions, PerfTracker perfTracker)
        {
            await NewDatabaseAsync();

            using (FdbDatabase db = await OpenDatabaseAsync())
            {
                IEnumerator <TestData> enumerator = data.GetEnumerator();

                return(WriteInternal(operation, enumerator, itemsPerTransaction, numberOfTransactions, perfTracker, db));
            }
        }
Esempio n. 5
0
        private async Task <PerformanceRecord> ReadAsync(string operation, IEnumerable <uint> ids, PerfTracker perfTracker)
        {
            Stopwatch sw = Stopwatch.StartNew();

            using (FdbDatabase db = await OpenDatabaseAsync())
            {
                await ReadInternalAsync(ids, perfTracker, db);
            }

            sw.Stop();

            return(new PerformanceRecord
            {
                Operation = operation,
                Time = DateTime.Now,
                Duration = sw.ElapsedMilliseconds,
                ProcessedItems = ids.Count()
            });
        }
Esempio n. 6
0
        private async Task <Tuple <List <PerformanceRecord>, long> > WriteParallelAsync(string operation,
                                                                                        IEnumerable <TestData> data,
                                                                                        int itemsPerTransaction, int numberOfTransactions, PerfTracker perfTracker, int numberOfThreads)
        {
            await NewDatabaseAsync();

            using (FdbDatabase db = await OpenDatabaseAsync())
            {
                long elapsedMilliseconds;
                List <PerformanceRecord> records = ExecuteWriteWithParallel(
                    data,
                    numberOfTransactions,
                    itemsPerTransaction,
                    numberOfThreads,
                    (enumerator, itmsPerTransaction, nmbrOfTransactions) =>
                    WriteInternal(operation, enumerator, itmsPerTransaction, nmbrOfTransactions, perfTracker, db),
                    out elapsedMilliseconds);
                return(new Tuple <List <PerformanceRecord>, long>(records, elapsedMilliseconds));
            }
        }
Esempio n. 7
0
 private List<PerformanceRecord> WriteInternal(string operation, IEnumerator<TestData> enumerator,
     long itemsPerTransaction, long numberOfTransactions, PerfTracker perfTracker, FdbDatabase db)
 {
     return
         WriteInternalAsync(operation, enumerator, itemsPerTransaction, numberOfTransactions, perfTracker, db)
             .Result;
 }
Esempio n. 8
0
        private async Task<List<PerformanceRecord>> WriteInternalAsync(string operation,
            IEnumerator<TestData> enumerator,
            long itemsPerTransaction, long numberOfTransactions, PerfTracker perfTracker, FdbDatabase db)
        {
            var sw = new Stopwatch();
            byte[] valueToWrite = null;
            var records = new List<PerformanceRecord>();

            var location = db.GlobalSpace;

            sw.Restart();
            for (int transactions = 0; transactions < numberOfTransactions; transactions++)
            {
                sw.Restart();
                using (IFdbTransaction tx = db.BeginTransaction())
                {
                    for (int i = 0; i < itemsPerTransaction; i++)
                    {
                        enumerator.MoveNext();

                        valueToWrite = GetValueToWrite(valueToWrite, enumerator.Current.ValueSize);

                        tx.Set(location.Pack(enumerator.Current.Id), Slice.Create(valueToWrite));
                    }

                    await tx.CommitAsync();
                    perfTracker.Record(sw.ElapsedMilliseconds);
                }

                sw.Stop();

                records.Add(new PerformanceRecord
                {
                    Operation = operation,
                    Time = DateTime.Now,
                    Duration = sw.ElapsedMilliseconds,
                    ProcessedItems = itemsPerTransaction
                });
            }

            sw.Stop();

            return records;
        }
Esempio n. 9
0
        private void LoadDatabase()
        {
            _fdbFile = new FdbFile(_file, i => _currentCount = i, out _tableCount);

            Database = new FdbDatabase(_fdbFile);
        }
Esempio n. 10
0
        private static async Task <long> ReadInternalAsync(IEnumerable <uint> ids, PerfTracker perfTracker, FdbDatabase db)
        {
            const int BATCH_SIZE = 1000;

            var list     = new List <int>(BATCH_SIZE);
            var location = db.GlobalSpace;

            Stopwatch sw = Stopwatch.StartNew();

            long v = 0;

            foreach (int id in ids)
            {
                list.Add(id);

                if (list.Count >= BATCH_SIZE)
                {
                    using (var tx = db.BeginReadOnlyTransaction())
                    {
                        var slices = await tx.GetValuesAsync(location.PackRange(list));

                        v += slices.Sum(x => x.Count);
                    }
                    list.Clear();
                }
            }

            if (list.Count > 0)
            {
                using (var tx = db.BeginReadOnlyTransaction())
                {
                    var slices = await tx.GetValuesAsync(location.PackRange(list));

                    v += slices.Sum(x => x.Count);
                }
            }

            perfTracker.Record(sw.ElapsedMilliseconds);
            return(v);
        }
Esempio n. 11
0
 private static long ReadInternal(IEnumerable <uint> ids, PerfTracker perfTracker, FdbDatabase db)
 {
     return(ReadInternalAsync(ids, perfTracker, db).Result);
 }
Esempio n. 12
0
 private void Start()
 {
     Database = new FdbDatabase(new FdbFile(Path));
 }
Esempio n. 13
0
 private List <PerformanceRecord> WriteInternal(string operation, IEnumerator <TestData> enumerator,
                                                long itemsPerTransaction, long numberOfTransactions, PerfTracker perfTracker, FdbDatabase db)
 {
     return
         (WriteInternalAsync(operation, enumerator, itemsPerTransaction, numberOfTransactions, perfTracker, db)
          .Result);
 }
Esempio n. 14
0
        private async Task <List <PerformanceRecord> > WriteInternalAsync(string operation,
                                                                          IEnumerator <TestData> enumerator,
                                                                          long itemsPerTransaction, long numberOfTransactions, PerfTracker perfTracker, FdbDatabase db)
        {
            var sw = new Stopwatch();

            byte[] valueToWrite = null;
            var    records      = new List <PerformanceRecord>();

            var location = db.GlobalSpace;

            sw.Restart();
            for (int transactions = 0; transactions < numberOfTransactions; transactions++)
            {
                sw.Restart();
                using (IFdbTransaction tx = db.BeginTransaction())
                {
                    for (int i = 0; i < itemsPerTransaction; i++)
                    {
                        enumerator.MoveNext();

                        valueToWrite = GetValueToWrite(valueToWrite, enumerator.Current.ValueSize);

                        tx.Set(location.Pack(enumerator.Current.Id), Slice.Create(valueToWrite));
                    }

                    await tx.CommitAsync();

                    perfTracker.Record(sw.ElapsedMilliseconds);
                }

                sw.Stop();

                records.Add(new PerformanceRecord
                {
                    Operation      = operation,
                    Time           = DateTime.Now,
                    Duration       = sw.ElapsedMilliseconds,
                    ProcessedItems = itemsPerTransaction
                });
            }

            sw.Stop();

            return(records);
        }
Esempio n. 15
0
			internal static Exception FailedToRegisterTransactionOnDatabase(IFdbTransaction transaction, FdbDatabase db)
			{
				Contract.Requires(transaction != null && db != null);
				return new InvalidOperationException(String.Format("Failed to register transaction #{0} with this instance of database {1}", transaction.Id, db.Name));
			}
Esempio n. 16
0
 private static long ReadInternal(IEnumerable<uint> ids, PerfTracker perfTracker, FdbDatabase db)
 {
     return ReadInternalAsync(ids, perfTracker, db).Result;
 }
Esempio n. 17
0
        private static async Task<long> ReadInternalAsync(IEnumerable<uint> ids, PerfTracker perfTracker, FdbDatabase db)
        {
            const int BATCH_SIZE = 1000;

            var list = new List<int>(BATCH_SIZE);
            var location = db.GlobalSpace;

            Stopwatch sw = Stopwatch.StartNew();

            long v = 0;
            foreach (int id in ids)
            {
                list.Add(id);

                if (list.Count >= BATCH_SIZE)
                {
                    using (var tx = db.BeginReadOnlyTransaction())
                    {
                        var slices = await tx.GetValuesAsync(location.PackRange(list));
                        v += slices.Sum(x=>x.Count);
                    }
                    list.Clear();
                }
            }

            if (list.Count > 0)
            {
                using (var tx = db.BeginReadOnlyTransaction())
                {
                    var slices = await tx.GetValuesAsync(location.PackRange(list));
                    v += slices.Sum(x => x.Count);
                 
                }
            }

            perfTracker.Record(sw.ElapsedMilliseconds);
            return v;
        }
Esempio n. 18
0
		private CancellationToken m_cancellation; //PERF: readonly struct

		#endregion

		#region Constructors...

		internal FdbTransaction(FdbDatabase db, FdbOperationContext context, int id, IFdbTransactionHandler handler, FdbTransactionMode mode)
		{
			Contract.Requires(db != null && context != null && handler != null);
			Contract.Requires(context.Database != null);

			m_context = context;
			m_database = db;
			m_id = id;
			//REVIEW: the operation context may already have created its own CTS, maybe we can merge them ?
			m_cts = CancellationTokenSource.CreateLinkedTokenSource(context.Cancellation);
			m_cancellation = m_cts.Token;

			m_readOnly = (mode & FdbTransactionMode.ReadOnly) != 0;
			m_handler = handler;
		}