public static void DumpLeaksCode(this IObjectDB db) { var leakedObjects = new Dictionary <ulong, bool>(); var leakedDictionaries = new Dictionary <ulong, bool>(); using var tr = db.StartReadOnlyTransaction(); using var visitor = new FindUnusedKeysVisitor(); visitor.ImportAllKeys(tr); visitor.Iterate(tr); foreach (var unseenKey in visitor.UnseenKeys()) { var isDict = unseenKey.Key[0] == 2; var isObject = unseenKey.Key[0] == 1; var r = new ByteArrayReader(unseenKey.Key); r.SkipUInt8(); var oid = r.ReadVUInt64(); if (isDict) { leakedDictionaries.TryAdd(oid, false); } else if (isObject) { leakedObjects.TryAdd(oid, false); } } WriteSplitIdList(leakedDictionaries.Keys, "dicts", 1000); WriteSplitIdList(leakedObjects.Keys, "objs", 1000); }
void OpenDb() { _db = new ObjectDB(); _db.Open(_lowDb, false, new DBOptions().WithoutAutoRegistration() .WithFieldHandlerLogger(new DefaultFieldHandlerLogger(s => _fieldHandlerLoggerMessages.Add(s)))); }
public ODBDictionaryConfiguration(IObjectDB odb, IFieldHandler keyHandler, IFieldHandler valueHandler, bool preferInline) { _odb = odb; _keyHandler = keyHandler; _valueHandler = valueHandler; _preferInline = preferInline; }
void OpenDB() { _lowDB = new KeyValueDB(); _lowDB.Open(_dbstream, false); _db = new ObjectDB(); _db.Open(_lowDB, true); }
public DBObjectFieldHandler(IObjectDB objectDB, Type type, bool indirect) : this(objectDB, type) { _objectDB = objectDB; _type = type; _typeName = null; _indirect = indirect; }
ODBSetFieldHandler(IObjectDB odb, byte[] configuration, IFieldHandler specializedKeyHandler) { _odb = odb; _typeConvertGenerator = odb.TypeConvertorGenerator; _configuration = configuration; _keysHandler = specializedKeyHandler; CreateConfiguration(); }
void OpenDb() { _logger = new LoggerMock(); _db = new ObjectDB { Logger = _logger }; _db.Open(_lowDb, false, new DBOptions().WithoutAutoRegistration().WithSelfHealing()); }
public DBObjectFieldHandler(IObjectDB objectDB, byte[] configuration) { _objectDB = objectDB; _configuration = configuration; _typeName = string.Intern(new ByteArrayReader(configuration).ReadString()); _indirect = false; CreateType(); }
public void GlobalSetup() { _db = new ObjectDB(); var directory = Path.Combine(Directory.GetCurrentDirectory(), "BTDBDist"); Directory.CreateDirectory(directory); Console.WriteLine($"GlobalSetup, db: {directory}"); _db.Open(new KeyValueDB(new OnDiskFileCollection(directory)), true); using var tr = _db.StartTransaction(); _creator = tr.InitRelation <IPersonTable>("Person"); var personTable = _creator(tr); if (personTable.CountByCountry(Country.Czech) > 0) { return; } var nationality = Country.Czech; var slovakiaCount = 0; var czechCount = 0; for (ulong i = 0; i < TotalRecords; i++) { personTable.Insert(new Person(i, $"Name{i}", nationality, 0)); if (i % 2 == 0 && slovakiaCount < SlovakiaTotal) { nationality = Country.Slovakia; slovakiaCount++; } else if (czechCount < CzechTotal) { nationality = Country.Czech; czechCount++; } else { nationality = nationality switch { Country.Czech => Country.Poland, Country.Poland => Country.Germany, Country.Germany => Country.Poland, Country.Slovakia => Country.Poland, _ => nationality }; } } foreach (var countryType in Enum.GetValues(typeof(Country))) { var count = personTable.CountByCountry((Country)countryType); Console.WriteLine($"{(Country) countryType} Total: {count}"); } tr.Commit(); }
ODBDictionaryFieldHandler(IObjectDB odb, byte[] configuration, int configurationId, IFieldHandler specializedKeyHandler, IFieldHandler specializedValueHandler) { _odb = odb; _fieldHandlerFactory = odb.FieldHandlerFactory; _typeConvertorGenerator = odb.TypeConvertorGenerator; _configuration = configuration; _keysHandler = specializedKeyHandler; _valuesHandler = specializedValueHandler; CreateConfiguration(); }
void OpenDb() { _db = new ObjectDB(); _db.Open(_lowDb, false, new DBOptions().WithSymmetricCipher(new AesGcmSymmetricCipher(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }))); }
public DBObjectFieldHandler(IObjectDB objectDB, Type type) { _objectDB = objectDB; _type = Unwrap(type); _indirect = _type != type; _typeName = _objectDB.RegisterType(_type); var writer = new ByteBufferWriter(); writer.WriteString(_typeName); _configuration = writer.Data.ToByteArray(); }
public ODBDictionaryFieldHandler(IObjectDB odb, byte[] configuration) { _odb = odb; _fieldHandlerFactory = odb.FieldHandlerFactory; _typeConvertorGenerator = odb.TypeConvertorGenerator; _configuration = configuration; var reader = new ByteArrayReader(configuration); _keysHandler = _fieldHandlerFactory.CreateFromReader(reader, FieldHandlerOptions.Orderable | FieldHandlerOptions.AtEndOfStream); _valuesHandler = _fieldHandlerFactory.CreateFromReader(reader, FieldHandlerOptions.None); CreateConfiguration(); }
void OpenDb() { _db = new ObjectDB(); _db.Open(_lowDb, false, new DBOptions() .WithoutAutoRegistration() .WithFieldHandlerLogger(new DefaultFieldHandlerLogger(s => _fieldHandlerLoggerMessages.Add(s))) .WithSymmetricCipher(new AesGcmSymmetricCipher(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }))); }
public ODBSetFieldHandler(IObjectDB odb, Type type, IFieldHandlerFactory fieldHandlerFactory) { _odb = odb; _typeConvertGenerator = odb.TypeConvertorGenerator; _type = type; _keysHandler = fieldHandlerFactory.CreateFromType(type.GetGenericArguments()[0], FieldHandlerOptions.Orderable | FieldHandlerOptions.AtEndOfStream); var writer = new ByteBufferWriter(); writer.WriteFieldHandler(_keysHandler); _configuration = writer.Data.ToByteArray(); CreateConfiguration(); }
public ODBSetFieldHandler(IObjectDB odb, byte[] configuration) { _odb = odb; var fieldHandlerFactory = odb.FieldHandlerFactory; _typeConvertGenerator = odb.TypeConvertorGenerator; _configuration = configuration; var reader = new SpanReader(configuration); _keysHandler = fieldHandlerFactory.CreateFromReader(ref reader, FieldHandlerOptions.Orderable | FieldHandlerOptions.AtEndOfStream); CreateConfiguration(); }
public ODBDictionaryFieldHandler(IObjectDB odb, Type type) { _odb = odb; _fieldHandlerFactory = odb.FieldHandlerFactory; _typeConvertorGenerator = odb.TypeConvertorGenerator; _type = type; _keysHandler = _fieldHandlerFactory.CreateFromType(type.GetGenericArguments()[0], FieldHandlerOptions.Orderable | FieldHandlerOptions.AtEndOfStream); _valuesHandler = _fieldHandlerFactory.CreateFromType(type.GetGenericArguments()[1], FieldHandlerOptions.None); var writer = new ByteBufferWriter(); writer.WriteFieldHandler(_keysHandler); writer.WriteFieldHandler(_valuesHandler); _configuration = writer.Data.ToByteArray(); CreateConfiguration(); }
public DBObjectFieldHandler(IObjectDB objectDb, byte[] configuration) { _objectDb = objectDb; _configuration = configuration; if (configuration.Length == 0) { _typeName = null; } else { _typeName = string.Intern(new ByteArrayReader(configuration).ReadString() !); _indirect = false; } CreateType(); }
public ODBDictionaryFieldHandler(IObjectDB odb, Type type, IFieldHandlerFactory fieldHandlerFactory) { _odb = odb; _typeConvertGenerator = odb.TypeConvertorGenerator; _type = type; _keysHandler = fieldHandlerFactory.CreateFromType(type.GetGenericArguments()[0], FieldHandlerOptions.Orderable | FieldHandlerOptions.AtEndOfStream); _valuesHandler = fieldHandlerFactory.CreateFromType(type.GetGenericArguments()[1], FieldHandlerOptions.None); var writer = new SpanWriter(); writer.WriteFieldHandler(_keysHandler); writer.WriteFieldHandler(_valuesHandler); _configuration = writer.GetSpan().ToArray(); CreateConfiguration(); }
public DBObjectFieldHandler(IObjectDB objectDb, Type type) { _objectDb = objectDb; _type = Unwrap(type); _indirect = _type != type; if (_type.IsInterface || _type.IsAbstract) { _typeName = null; _configuration = Array.Empty <byte>(); } else { _typeName = (_objectDb as ObjectDB)?.RegisterType(_type, false); var writer = new ByteBufferWriter(); writer.WriteString(_typeName); _configuration = writer.Data.ToByteArray(); } }
public PersistentBuildCache(string dir) { var cacheIndex = 0; while (cacheIndex < 100) { _mutex = new Mutex(false, @"Global\bbcoreCache" + cacheIndex); if (_mutex.WaitOne(10)) { break; } _mutex.Dispose(); _mutex = null; cacheIndex++; } if (_mutex == null) { return; } _dir = dir + "/cache" + (cacheIndex == 0 ? "" : cacheIndex.ToString()); if (!new DirectoryInfo(_dir).Exists) { Directory.CreateDirectory(_dir); } _diskFileCollection = new OnDiskFileCollection(_dir); _kvdb = new KeyValueDB(new KeyValueDBOptions { FileCollection = _diskFileCollection, Compression = new SnappyCompressionStrategy(), FileSplitSize = 100000000 }); _odb = new ObjectDB(); _odb.Open(_kvdb, false); using (var tr = _odb.StartWritingTransaction().Result) { _tsConfiguration = tr.InitRelation <ITSConfigurationTable>("tsconf"); _tsRelation = tr.InitRelation <ITSFileBuildCacheTable>("ts"); _tsHashedContent = tr.InitRelation <IHashedContentTable>("hashedContent"); tr.Commit(); } }
void Initialize() { _dbdir = Path.GetTempPath() + "/deleteMeDB"; Directory.Delete(_dbdir, true); Directory.CreateDirectory(_dbdir); _fc = new OnDiskFileCollection(_dbdir); _kvdb = new KeyValueDB(new KeyValueDBOptions { Compression = new SnappyCompressionStrategy(), FileSplitSize = 100 * 1024 * 1024, FileCollection = _fc }); _kvdb.Logger = this; _odb = new ObjectDB(); _odb.Open(_kvdb, false); using (var tr = _odb.StartWritingTransaction().GetAwaiter().GetResult()) { _personRelation = tr.InitRelation <IPersonTable>("Person"); tr.Commit(); } }
public static void DumpLeaks(this IObjectDB db) { using (var tr = db.StartReadOnlyTransaction()) using (var visitor = new FindUnusedKeysVisitor()) { visitor.ImportAllKeys(tr); var iterator = visitor.Iterate(tr); visitor.DumpUnseenKeys(); var leakedObjects = new List <ulong>(); foreach (var unseenKey in visitor.UnseenKeys()) { if (unseenKey.Key[0] == 1) { try { var r = new ByteArrayReader(unseenKey.Key); r.SkipUInt8(); var oid = r.ReadVUInt64(); leakedObjects.Add(oid); } catch (Exception ex) { Console.WriteLine($"Leak found but error has occured while reading: {ex.Message}"); } } } if (leakedObjects.Count > 0) { Console.WriteLine("--- OBJECTS ---"); var consoleVisitor = new ToConsoleVisitorNice(); foreach (var oid in leakedObjects) { iterator.IterateUnseenOid(oid, consoleVisitor); Console.WriteLine("------"); } } } }
public PersistentBuildCache(string dir) { _dir = dir + "/cache"; if (!new DirectoryInfo(_dir).Exists) { Directory.CreateDirectory(_dir); } _diskFileCollection = new OnDiskFileCollection(_dir); _kvdb = new KeyValueDB(new KeyValueDBOptions { FileCollection = _diskFileCollection, Compression = new SnappyCompressionStrategy(), FileSplitSize = 100000000 }); _odb = new ObjectDB(); _odb.Open(_kvdb, false); using (var tr = _odb.StartWritingTransaction().Result) { _tsConfiguration = tr.InitRelation <ITSConfigurationTable>("tsconf"); _tsRelation = tr.InitRelation <ITSFileBuildCacheTable>("ts"); tr.Commit(); } }
void OpenDb() { _db = new ObjectDB(); _db.Open(_lowDb, false); }
public RelationODBFieldHandlerFactory(IObjectDB odb) : base(odb) { }
public DefaultODBFieldHandlerFactory(IObjectDB odb) : base(odb) { _odb = odb; }
public ODBDictionaryConfiguration(IObjectDB odb, IFieldHandler keyHandler, IFieldHandler?valueHandler) { _odb = odb; KeyHandler = keyHandler; ValueHandler = valueHandler; }
void OpenDb() { _db = new ObjectDB(); _db.Open(_lowDb, false, new DBOptions().WithoutAutoRegistration().WithCustomType2NameRegistry(_registry)); }
void OpenDb() { _db = new ObjectDB(); _db.Open(_lowDb, false, new DBOptions().WithoutAutoRegistration()); }
public ODBDictionaryConfiguration(IObjectDB odb, IFieldHandler keyHandler, IFieldHandler valueHandler) { _odb = odb; _keyHandler = keyHandler; _valueHandler = valueHandler; }