public void CreateDataWithBackupServer() { int loops = 30000; int j; using (ServerClientSession session = new ServerClientSession(s_systemDir, systemHost, 1000, true, inMemoryOnly)) { Man aMan = null; Woman aWoman = null; const bool isBackupLocation = true; session.BeginUpdate(); // we need to have backup locations special since server is not supposed to do encryption or compression DatabaseLocation backupLocation = new DatabaseLocation(backupHost, backupDir, backupLocationStartDbNum, UInt32.MaxValue, session, PageInfo.compressionKind.LZ4, PageInfo.encryptionKind.noEncryption, isBackupLocation, session.DatabaseLocations.Default()); session.NewLocation(backupLocation); session.Commit(); session.BeginUpdate(); for (j = 1; j <= loops; j++) { aMan = new Man(null, aMan, DateTime.Now); session.Persist(aMan); aWoman = new Woman(aMan, aWoman); session.Persist(aWoman); aMan.m_spouse = new VelocityDb.WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman); if (j % 1000000 == 0) Console.WriteLine("Loop # " + j); } UInt64 id = aWoman.Id; Console.WriteLine("Commit, done Loop # " + j); session.Commit(); } }
public void CreateDataWithBackupServer() { int loops = 30000; int j; using (ServerClientSession session = new ServerClientSession(s_systemDir, systemHost, 1000, true, inMemoryOnly)) { Man aMan = null; Woman aWoman = null; const bool isBackupLocation = true; session.BeginUpdate(); // we need to have backup locations special since server is not supposed to do encryption or compression DatabaseLocation backupLocation = new DatabaseLocation(backupHost, backupDir, backupLocationStartDbNum, UInt32.MaxValue, session, PageInfo.compressionKind.LZ4, PageInfo.encryptionKind.noEncryption, isBackupLocation, session.DatabaseLocations.Default()); session.NewLocation(backupLocation); session.Commit(); session.BeginUpdate(); for (j = 1; j <= loops; j++) { aMan = new Man(null, aMan, DateTime.Now); session.Persist(aMan); aWoman = new Woman(aMan, aWoman); session.Persist(aWoman); aMan.m_spouse = new VelocityDb.WeakIOptimizedPersistableReference <VelocityDbSchema.Person>(aWoman); if (j % 1000000 == 0) { Console.WriteLine("Loop # " + j); } } UInt64 id = aWoman.Id; Console.WriteLine("Commit, done Loop # " + j); session.Commit(); } }
public void schemaUpdateMultipleSessions() { Assert.Throws <OptimisticLockingFailed>(() => { using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginUpdate(); Placement place = new Placement(555, 1, 1, 10, 10); Simple1 s1 = new Simple1(1); s1.Persist(place, session); s1 = null; using (ServerClientSession session2 = new ServerClientSession(systemDir)) { Placement place2 = new Placement(556, 1, 1, 10, 10); session2.BeginUpdate(); Simple2 s2 = new Simple2(2); s2.Persist(place2, session2); s2 = null; session.Commit(); session2.Commit(); // optemistic locking will fail due to session2 working with a stale schema (not the one updated by session 1) session.BeginUpdate(); s1 = (Simple1)session.Open(555, 1, 1, false); s2 = (Simple2)session.Open(556, 1, 1, false); session.Commit(); session2.BeginUpdate(); s1 = (Simple1)session2.Open(555, 1, 1, false); s2 = (Simple2)session2.Open(556, 1, 1, false); session2.Commit(); } } }); }
public void schemaUpdateMultipleSessions() { using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginUpdate(); Placement place = new Placement(555, 1, 1, 10, 10); Simple1 s1 = new Simple1(1); s1.Persist(place, session); s1 = null; using (ServerClientSession session2 = new ServerClientSession(systemDir)) { Placement place2 = new Placement(556, 1, 1, 10, 10); session2.BeginUpdate(); Simple2 s2 = new Simple2(2); s2.Persist(place2, session2); s2 = null; session.Commit(); session2.Commit(); // optemistic locking will fail due to session2 working with a stale schema (not the one updated by session 1) session.BeginUpdate(); s1 = (Simple1)session.Open(555, 1, 1, false); s2 = (Simple2)session.Open(556, 1, 1, false); session.Commit(); session2.BeginUpdate(); s1 = (Simple1)session2.Open(555, 1, 1, false); s2 = (Simple2)session2.Open(556, 1, 1, false); session2.Commit(); } } }
static void UpdaterThread() { using (ServerClientSession session = new ServerClientSession(s_systemDir)) { session.BeginUpdate(); Person Mats = new Person("Mats", "Persson", 22, 1234, null, null); session.Persist(Mats); Woman Kinga = new Woman("Kinga", "Persson", 56, 234, null, Mats); foreach (Person p in session.AllObjects<Person>(true)) { p.Age = (ushort) (p.Age + 1); } session.Persist(Kinga); session.Commit(); // 5 events Thread.Sleep(5000); session.BeginUpdate(); Woman Lidia = new Woman("Lidia", "Persson", 22, 1234, null, null); session.Persist(Lidia); session.Commit(); // 0 events Thread.Sleep(500); session.BeginUpdate(); Woman Margareta = new Woman("Margareta", "Persson", 98, 1234, null, null); session.Persist(Margareta); session.Commit(); // 1 event Thread.Sleep(500); session.BeginUpdate(); Woman Oliwia = new Woman("Oliwia", "Persson", 50, 1234, null, null); session.Persist(Oliwia); session.Commit(); // 0 events Thread.Sleep(500); session.BeginUpdate(); foreach (Woman p in session.AllObjects<Woman>()) { p.Age = (ushort) (p.Age + 1); } session.Commit(); // 3 events session.BeginUpdate(); foreach (Woman p in session.AllObjects<Woman>()) { p.Age = (ushort)(p.Age + 1); } session.Commit(); // 3 events } }
public void test() { ServerClientSession VelocityServerSession = new ServerClientSession(systemDir, "localhost"); Woman TmpSynchronizationData = new Woman();//APSSynchData TmpSynchronizationData = default(APSSynchData); // APSSynchData(); //TmpSynchronizationData.SyncedElections = new VelocityDbList<Man>(); VelocityServerSession.BeginUpdate(); TmpSynchronizationData.Persist(VelocityServerSession, TmpSynchronizationData); VelocityServerSession.Commit(); //SaveToDisk("4.odb", DatabasePath + "\\4.odb"); VelocityServerSession.BeginUpdate(); }
public void CreateLocationSameHostServer(bool optimisticLocking) { using (ServerClientSession session = new ServerClientSession(systemDir, Dns.GetHostName(), 2000, optimisticLocking)) { session.BeginUpdate(); DatabaseLocation remoteLocation = new DatabaseLocation(Dns.GetHostName(), location2Dir, locationStartDbNum, locationEndDbNum, session, PageInfo.compressionKind.LZ4, 0); remoteLocation = session.NewLocation(remoteLocation); Database database = session.NewDatabase(remoteLocation.StartDatabaseNumber); Assert.NotNull(database); session.Commit(); } using (ServerClientSession session = new ServerClientSession(systemDir, Dns.GetHostName(), 2000, optimisticLocking)) { session.BeginUpdate(); Database database = session.OpenDatabase(locationStartDbNum, false); Assert.NotNull(database); session.DeleteDatabase(database); session.Commit(); } using (ServerClientSession session = new ServerClientSession(systemDir, Dns.GetHostName(), 2000, optimisticLocking)) { session.BeginUpdate(); foreach (DatabaseLocation loc in session.DatabaseLocations) { Console.WriteLine(loc.ToStringDetails(session, false)); } session.DeleteLocation(session.DatabaseLocations.LocationForDb(locationStartDbNum)); foreach (DatabaseLocation loc in session.DatabaseLocations) { Console.WriteLine(loc.ToStringDetails(session, false)); } session.Commit(); } }
static void Main(string[] args) { SessionBase.DoWindowsAuthentication = false; // Make sure to use the same setting when starting VelocityDBServer, see http://www.velocitydb.com/UserGuide.aspx try { // initial DatabaseLocation directory and hostname using (ServerClientSession session = new ServerClientSession(systemDir, System.Net.Dns.GetHostName())) { session.BeginUpdate(); // your code here Person robinHood = new Person("Robin", "Hood", 30); Person billGates = new Person("Bill", "Gates", 56, robinHood); Person steveJobs = new Person("Steve", "Jobs", 56, billGates); robinHood.BestFriend = billGates; session.Persist(steveJobs); steveJobs.Friends.Add(billGates); steveJobs.Friends.Add(robinHood); billGates.Friends.Add(billGates); robinHood.Friends.Add(steveJobs); session.Commit(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public void CreateLocationSameHostServer(bool optimisticLocking) { using (ServerClientSession session = new ServerClientSession(systemDir, Dns.GetHostName(), 2000, optimisticLocking)) { session.BeginUpdate(); DatabaseLocation remoteLocation = new DatabaseLocation(Dns.GetHostName(), location2Dir, locationStartDbNum, locationEndDbNum, session, PageInfo.compressionKind.LZ4, 0); remoteLocation = session.NewLocation(remoteLocation); Database database = session.NewDatabase(remoteLocation.StartDatabaseNumber); Assert.NotNull(database); session.Commit(); } using (ServerClientSession session = new ServerClientSession(systemDir, Dns.GetHostName(), 2000, optimisticLocking)) { session.BeginUpdate(); Database database = session.OpenDatabase(locationStartDbNum, false); Assert.NotNull(database); session.DeleteDatabase(database); session.Commit(); } using (ServerClientSession session = new ServerClientSession(systemDir, Dns.GetHostName(), 2000, optimisticLocking)) { session.BeginUpdate(); foreach (DatabaseLocation loc in session.DatabaseLocations) Console.WriteLine(loc.ToStringDetails(session, false)); session.DeleteLocation(session.DatabaseLocations.LocationForDb(locationStartDbNum)); foreach (DatabaseLocation loc in session.DatabaseLocations) Console.WriteLine(loc.ToStringDetails(session, false)); session.Commit(); } }
static void Main(string[] args) { SessionBase.s_serverTcpIpPortNumber = 7032; SessionBase.DoWindowsAuthentication = false; // Make sure to use the same setting when starting VelocityDBServer, see http://www.velocitydb.com/UserGuide.aspx try { // initial DatabaseLocation directory and hostname using (ServerClientSession session = new ServerClientSession(systemDir, System.Net.Dns.GetHostName())) { session.BeginUpdate(); // your code here Person robinHood = new Person("Robin", "Hood", 30); Person billGates = new Person("Bill", "Gates", 56, robinHood); Person steveJobs = new Person("Steve", "Jobs", 56, billGates); robinHood.BestFriend = billGates; session.Persist(steveJobs); steveJobs.Friends.Add(billGates); steveJobs.Friends.Add(robinHood); billGates.Friends.Add(billGates); robinHood.Friends.Add(steveJobs); session.Commit(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public void CreateMoreDataWithBackupServer() { int loops = 1000; int j; using (ServerClientSession session = new ServerClientSession(s_systemDir, systemHost, 1000, true, inMemoryOnly)) { Man aMan = null; Woman aWoman = null; session.BeginUpdate(); for (j = 1; j <= loops; j++) { aMan = new Man(null, aMan, DateTime.Now); session.Persist(aMan); aWoman = new Woman(aMan, aWoman); session.Persist(aWoman); aMan.m_spouse = new VelocityDb.WeakIOptimizedPersistableReference <VelocityDbSchema.Person>(aWoman); if (j % 1000000 == 0) { Console.WriteLine("Loop # " + j); } } UInt64 id = aWoman.Id; Console.WriteLine("Commit, done Loop # " + j); session.FlushUpdates(); ReadSomeData(); // read some with uncommited cached server data session.Commit(); } }
public void CreateMoreDataWithBackupServer() { int loops = 30000; UInt16 objectsPerPage = 350; UInt16 pagesPerDatabase = 65000; int j; using (ServerClientSession session = new ServerClientSession(systemDir, Dns.GetHostName())) { Placement place = new Placement(11, 1, 1, objectsPerPage, pagesPerDatabase); Man aMan = null; Woman aWoman = null; session.BeginUpdate(); for (j = 1; j <= loops; j++) { aMan = new Man(null, aMan, DateTime.Now); aMan.Persist(place, session); aWoman = new Woman(aMan, aWoman); aWoman.Persist(place, session); aMan.m_spouse = new WeakIOptimizedPersistableReference <VelocityDbSchema.Person>(aWoman); if (j % 1000000 == 0) { Console.WriteLine("Loop # " + j); } } UInt64 id = aWoman.Id; Console.WriteLine("Commit, done Loop # " + j); session.Commit(); } }
public void fCreateDatabasesPreSizeServer() { Database database; using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginUpdate(); for (uint i = 50000100; i < 50000200; i++) { database = session.NewDatabase(i, i - 50000100, "myServerSetDbName"); Assert.NotNull(database); } session.Commit(); } using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginUpdate(); for (uint i = 50000000; i < 50000200; i++) { database = session.OpenDatabase(i); Assert.NotNull(database); } session.Commit(); } }
public void CreateMoreDataWithBackupServer() { int loops = 1000; int j; using (ServerClientSession session = new ServerClientSession(s_systemDir, systemHost, 1000, true, inMemoryOnly)) { Man aMan = null; Woman aWoman = null; session.BeginUpdate(); for (j = 1; j <= loops; j++) { aMan = new Man(null, aMan, DateTime.Now); session.Persist(aMan); aWoman = new Woman(aMan, aWoman); session.Persist(aWoman); aMan.m_spouse = new VelocityDb.WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman); if (j % 1000000 == 0) Console.WriteLine("Loop # " + j); } UInt64 id = aWoman.Id; Console.WriteLine("Commit, done Loop # " + j); session.FlushUpdates(); ReadSomeData(); // read some with uncommited cached server data session.Commit(); } }
public void RestoreAllViaServer() { using (ServerClientSession session = new ServerClientSession(systemDir, null, 2000, false)) // don't use optimistic locking for restore { session.BeginUpdate(); DatabaseLocation backupLocation = new DatabaseLocation(Dns.GetHostName(), backupDir, backupLocationStartDbNum, UInt32.MaxValue, session, PageInfo.compressionKind.None, PageInfo.encryptionKind.noEncryption, true, session.DatabaseLocations.Default()); session.RestoreFrom(backupLocation, DateTime.Now); session.Commit(false); } }
public void serverSessionOverhead(int numberOfSessions) { for (int i = 0; i < numberOfSessions; i++) { using (ServerClientSession session = new ServerClientSession(systemDir2, systemHost3)) { session.BeginUpdate(); session.Commit(); } } }
public void UseManyFederations() { for (int i = 0; i < 50; i++) { using (SessionBase session = new ServerClientSession("Federation" + i)) { session.BeginUpdate(); session.Commit(); } } }
public void UseManyFederations() { for (int i = 0; i < 50; i++) { using (SessionBase session = new ServerClientSession("Federation" + i)) { session.BeginUpdate(); session.Commit(); } } }
public static void CreateUser() { using (ServerClientSession session = new ServerClientSession(systemDir, systemHost)) { session.BeginUpdate(); Graph g = Graph.Open(session); VertexType movieType = g.FindVertexType("MOVIE"); PropertyType movieTitleType = movieType.FindProperty("TITLE"); PropertyType movieYearType = movieType.FindProperty("YEAR"); for (int i = 1; i < 50; i++) { Vertex mVickyCB = movieType.NewVertex(); mVickyCB.SetProperty(movieTitleType, "Vicky Cristina Barcelona" + i); mVickyCB.SetProperty(movieYearType, (int)(2008 + i)); session.Commit(); session.BeginUpdate(); Thread.Sleep(1000); } } }
public void gDeleteDatabasesServer() { Database database; using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginUpdate(); for (uint i = 50000000; i < 50000100; i++) { database = session.OpenDatabase(i); session.DeleteDatabase(database); } session.Commit(); } }
public void DeleteBackupLocation() { using (ServerClientSession session = new ServerClientSession(s_systemDir, systemHost, 1000, true, inMemoryOnly)) { session.BeginUpdate(); DatabaseLocation backupLocation = session.DatabaseLocations.LocationForDb(backupLocationStartDbNum); List <Database> dbList = session.OpenLocationDatabases(backupLocation, true); foreach (Database db in dbList) { session.DeleteDatabase(db); } session.DeleteLocation(backupLocation); session.Commit(); } }
public void RestoreToBackupServer() { using (ServerClientSession session = new ServerClientSession(s_systemDir, systemHost)) { session.ClearServerCache(); // normally don't use this function but use it here to simulate a server going down and restarting } using (ServerClientSession session = new ServerClientSession(s_systemDir, backupHost, 1000, true, inMemoryOnly)) { session.BeginUpdate(); DatabaseLocation backupLocation = new DatabaseLocation(backupHost, backupDir, backupLocationStartDbNum, UInt32.MaxValue, session, PageInfo.compressionKind.LZ4, PageInfo.encryptionKind.noEncryption, true, session.DatabaseLocations.Default()); session.RestoreFrom(backupLocation, DateTime.MaxValue); session.Commit(false, true); } }
static void UpdaterThread() { using (ServerClientSession session = new ServerClientSession(s_systemDir)) { session.BeginUpdate(); Person Mats = new Person("Mats", "Persson", 22, 1234, null, null); session.Persist(Mats); Woman Kinga = new Woman("Kinga", "Persson", 56, 234, null, Mats); foreach (Person p in session.AllObjects <Person>(true)) { p.Age = (ushort)(p.Age + 1); } session.Persist(Kinga); session.Commit(); // 5 events Thread.Sleep(5000); session.BeginUpdate(); Woman Lidia = new Woman("Lidia", "Persson", 22, 1234, null, null); session.Persist(Lidia); session.Commit(); // 0 events Thread.Sleep(500); session.BeginUpdate(); Woman Margareta = new Woman("Margareta", "Persson", 98, 1234, null, null); session.Persist(Margareta); session.Commit(); // 1 event Thread.Sleep(500); session.BeginUpdate(); Woman Oliwia = new Woman("Oliwia", "Persson", 50, 1234, null, null); session.Persist(Oliwia); session.Commit(); // 0 events Thread.Sleep(500); session.BeginUpdate(); foreach (Woman p in session.AllObjects <Woman>()) { p.Age = (ushort)(p.Age + 1); } session.Commit(); // 3 events session.BeginUpdate(); foreach (Woman p in session.AllObjects <Woman>()) { p.Age = (ushort)(p.Age + 1); } session.Commit(); // 3 events } }
public void DeleteDefaultLocation() { using (ServerClientSession session = new ServerClientSession(s_systemDir, systemHost, 1000, true, inMemoryOnly)) { session.BeginUpdate(); DatabaseLocation defaultLocation = session.DatabaseLocations.Default(); List <Database> dbList = session.OpenLocationDatabases(defaultLocation, true); foreach (Database db in dbList) { if (db.DatabaseNumber > Database.InitialReservedDatabaseNumbers) { session.DeleteDatabase(db); } } session.DeleteLocation(defaultLocation); session.Commit(); } }
static void Main(string[] args) { using (ServerClientSession session = new ServerClientSession(s_systemDir)) { session.BeginUpdate(); File.Copy(s_licenseDbFile, Path.Combine(s_systemDir, "4.odb"), true); session.RegisterClass(typeof(Woman)); session.RegisterClass(typeof(Man)); session.SubscribeToChanges(typeof(Person)); session.SubscribeToChanges(typeof(Woman), "OlderThan50"); Person robinHood = new Person("Robin", "Hood", 30, 1234, null, null); session.Persist(robinHood); Person billGates = new Person("Bill", "Gates", 56, 234, robinHood, null); session.Persist(billGates); Person steveJobs = new Person("Steve", "Jobs", 56, 456, billGates, null); session.Persist(steveJobs); session.Commit(); Thread t = new Thread(UpdaterThread); t.Start(); Thread.Sleep(600); for (int i = 0; i < 50; i++) { List <Oid> changes = session.BeginReadWithEvents(); if (changes.Count == 0) { Console.WriteLine("No changes events at: " + DateTime.Now.ToString("HH:mm:ss:fff")); Thread.Sleep(250); } foreach (Oid id in changes) { object obj = session.Open(id); Console.WriteLine("Received change event for: " + obj + " at: " + DateTime.Now.ToString("HH:mm:ss:fff"));; //session.UnsubscribeToChanges(typeof(Person)); } Console.WriteLine(); session.Commit(); } t.Join(); } }
static void Main(string[] args) { using (ServerClientSession session = new ServerClientSession(s_systemDir)) { session.BeginUpdate(); File.Copy(s_licenseDbFile, Path.Combine(s_systemDir, "4.odb"), true); session.RegisterClass(typeof(Woman)); session.RegisterClass(typeof(Man)); session.SubscribeToChanges(typeof(Person)); session.SubscribeToChanges(typeof(Woman), "OlderThan50"); Person robinHood = new Person("Robin", "Hood", 30, 1234, null, null); session.Persist(robinHood); Person billGates = new Person("Bill", "Gates", 56, 234, robinHood, null); session.Persist(billGates); Person steveJobs = new Person("Steve", "Jobs", 56, 456, billGates, null); session.Persist(steveJobs); session.Commit(); Thread t = new Thread(UpdaterThread); t.Start(); Thread.Sleep(600); for (int i = 0; i < 50; i++) { List<Oid> changes = session.BeginReadWithEvents(); if (changes.Count == 0) { Console.WriteLine("No changes events at: " + DateTime.Now.ToString("HH:mm:ss:fff")); Thread.Sleep(250); } foreach (Oid id in changes) { object obj = session.Open(id); Console.WriteLine("Received change event for: " + obj + " at: " + DateTime.Now.ToString("HH:mm:ss:fff"));; //session.UnsubscribeToChanges(typeof(Person)); } Console.WriteLine(); session.Commit(); } t.Join(); } }
public void multipleServersOKCleanup() { using (ServerClientSession session = new ServerClientSession(systemDir, systemHost, 2000, false)) // TO DO, change back to use optimistic locking { //session.SetTraceDbActivity(0); session.BeginUpdate(); Database db = session.OpenDatabase(10000, true, false); if (db != null) { session.DeleteDatabase(db); } db = session.OpenDatabase(20001, true, false); if (db != null) { session.DeleteDatabase(db); } db = session.OpenDatabase(30001, true, false); if (db != null) { session.DeleteDatabase(db); } db = session.OpenDatabase(40001, true, false); if (db != null) { session.DeleteDatabase(db); } session.Commit(); if (Directory.Exists(copyDir)) { Directory.Delete(copyDir, true); } } System.GC.Collect(); System.GC.WaitForPendingFinalizers(); using (ServerClientSession session = new ServerClientSession(systemDir, systemHost)) { Assert.True(session.OptimisticLocking); } }
public void Bug1Test() { _count++; VelocityDbSchema.Samples.Sample1.Person person; var sess = new ServerClientSession(systemDir); sess.BeginUpdate(); var count = 10000; var tw = new Stopwatch(); tw.Start(); for (int i = 0; i < count; i++) { person = new VelocityDbSchema.Samples.Sample1.Person("Bill" + i, "Gates", 56); person.Persist(sess, person); } tw.Stop(); Console.WriteLine("{0} records in {1} ms., Count is: {2}", _count, tw.ElapsedMilliseconds, _count); sess.Commit(); sess.Dispose(); }
public void AppendFile() { Placement place = new Placement(798, 1, 1, 1, UInt16.MaxValue); using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginUpdate(); ObjWithArray a = new ObjWithArray(10); a.Persist(place, session); session.Commit(); // commit Database 798 } place = new Placement(798, 2, 1, 100, UInt16.MaxValue); for (int i = 0; i < 25; i++) { using (ServerClientSession session = new ServerClientSession(systemDir)) { //session.SetTraceAllDbActivity(); session.BeginUpdate(); for (int j = 0; j < 1000; j++) { ObjWithArray a = new ObjWithArray(j * 10); a.Persist(place, session); } session.FlushUpdates(); session.FlushUpdatesServers(); // check if this will cause file to be appended Database db = session.NewDatabase(3567); using (ServerClientSession session2 = new ServerClientSession(systemDir)) { session2.BeginUpdate(); ObjWithArray a = new ObjWithArray(10); a.Persist(place, session2); session2.Commit(); } session.Abort(); // appended page space now unused? Need tidy? } } }
public void AppendFile() { Placement place = new Placement(798, 1, 1, 1, UInt16.MaxValue); using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginUpdate(); ObjWithArray a = new ObjWithArray(10); a.Persist(place, session); session.Commit(); // commit Database 798 } place = new Placement(798, 2, 1, 100, UInt16.MaxValue); for (int i = 0; i < 25; i++) { using (ServerClientSession session = new ServerClientSession(systemDir)) { //session.SetTraceAllDbActivity(); session.BeginUpdate(); for (int j = 0; j < 1000; j++) { ObjWithArray a = new ObjWithArray(j * 10); a.Persist(place, session); } session.FlushUpdates(); session.FlushUpdatesServers(); // check if this will cause file to be appended Database db = session.NewDatabase(3567); using (ServerClientSession session2 = new ServerClientSession(systemDir)) { session2.BeginUpdate(); ObjWithArray a = new ObjWithArray(10); a.Persist(place, session2); session2.Commit(); } session.Abort(); // appended page space now unused? Need tidy? } } }
public void SingleServerReaderSingleServerUpdater2(bool useReaderCommit) { const UInt32 dbNum = 567; using (ServerClientSession updater = new ServerClientSession(systemDir)) using (ServerClientSession reader = new ServerClientSession(systemDir, null, 2000, true, false, CacheEnum.No)) // CacheEnum.No or cache validating on session.Begin() - makes test fail { updater.BeginUpdate(); Database db = updater.OpenDatabase(dbNum, true, false); if (db != null) { updater.DeleteDatabase(db); } updater.Commit(); updater.BeginUpdate(); Man man; Placement place = new Placement(dbNum, 1, 1, 2); for (int i = 0; i < 100; i++) { man = new Man(); man.Persist(place, updater); } updater.Commit(); reader.BeginRead(); db = reader.OpenDatabase(dbNum); foreach (Page page in db) { Assert.True(page.PageInfo.VersionNumber == 1); } if (useReaderCommit) { reader.Commit(); } updater.BeginUpdate(); if (useReaderCommit) { reader.BeginRead(); } else { reader.ForceDatabaseCacheValidation(); } for (int i = 1; i < 25; i++) { db = reader.OpenDatabase(dbNum); foreach (Page page in db) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i); Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false); Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true); } } if (useReaderCommit) { reader.Commit(); reader.BeginRead(); } else { reader.ForceDatabaseCacheValidation(); } updater.Commit(); updater.BeginUpdate(); } Database db2 = reader.OpenDatabase(dbNum); db = updater.OpenDatabase(dbNum); for (int i = 25; i < 50; i++) { foreach (Page page in db) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i); Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true); } } updater.FlushUpdates(); // now server will see updated version of pages foreach (Page page in db2) { if (page.PageNumber > 0) { // BUG Nov 8, 2011 1.0.4.0 reader sees version 28 when it should see version 27 Assert.True(page.PageInfo.VersionNumber == (ulong)i); // reader should see the commited version of the page, not the uncommited updated version Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false); } } reader.ClearPageCache(); // required or else we will use cached page and Assert (see line above) will fail System.GC.Collect(); // force weak referenced pages to be garbage collected (again to avoid Assert failure) updater.Commit(); updater.BeginUpdate(); } reader.Commit(); updater.DeleteDatabase(db); updater.Commit(); } }
public void SingleServerReaderSingleServerUpdater2(bool useReaderCommit) { const UInt32 dbNum = 567; using (ServerClientSession updater = new ServerClientSession(systemDir)) using (ServerClientSession reader = new ServerClientSession(systemDir, null, 2000, true, false, CacheEnum.No)) // CacheEnum.No or cache validating on session.Begin() - makes test fail { updater.BeginUpdate(); Database db = updater.OpenDatabase(dbNum, true, false); if (db != null) updater.DeleteDatabase(db); updater.Commit(); updater.BeginUpdate(); Man man; Placement place = new Placement(dbNum, 1, 1, 2); for (int i = 0; i < 100; i++) { man = new Man(); man.Persist(place, updater); } updater.Commit(); reader.BeginRead(); db = reader.OpenDatabase(dbNum); foreach (Page page in db) Assert.True(page.PageInfo.VersionNumber == 1); if (useReaderCommit) reader.Commit(); updater.BeginUpdate(); if (useReaderCommit) reader.BeginRead(); else reader.ForceDatabaseCacheValidation(); for (int i = 1; i < 25; i++) { db = reader.OpenDatabase(dbNum); foreach (Page page in db) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i); Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false); Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true); } } if (useReaderCommit) { reader.Commit(); reader.BeginRead(); } else reader.ForceDatabaseCacheValidation(); updater.Commit(); updater.BeginUpdate(); } Database db2 = reader.OpenDatabase(dbNum); db = updater.OpenDatabase(dbNum); for (int i = 25; i < 50; i++) { foreach (Page page in db) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i); Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true); } } updater.FlushUpdates(); // now server will see updated version of pages foreach (Page page in db2) { if (page.PageNumber > 0) { // BUG Nov 8, 2011 1.0.4.0 reader sees version 28 when it should see version 27 Assert.True(page.PageInfo.VersionNumber == (ulong)i); // reader should see the commited version of the page, not the uncommited updated version Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false); } } reader.ClearPageCache(); // required or else we will use cached page and Assert (see line above) will fail System.GC.Collect(); // force weak referenced pages to be garbage collected (again to avoid Assert failure) updater.Commit(); updater.BeginUpdate(); } reader.Commit(); updater.DeleteDatabase(db); updater.Commit(); } }
public void SingleServerReaderSingleServerUpdater1() { ServerClientSession updater = new ServerClientSession(systemDir); ServerClientSession reader = new ServerClientSession(systemDir); const UInt32 dbNum = 345; try { updater.BeginUpdate(); Man man; Placement place = new Placement(dbNum, 1, 1, 2); for (int i = 0; i < 100; i++) { man = new Man(); man.Persist(place, updater); } updater.Commit(); reader.BeginRead(); Database db = reader.OpenDatabase(dbNum); foreach (Page page in db) Assert.True(page.PageInfo.VersionNumber == 1); reader.Commit(); updater.BeginUpdate(); reader.BeginRead(); for (int i = 1; i < 25; i++) { db = reader.OpenDatabase(dbNum); foreach (Page page in db) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i); Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false); Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true); } } reader.Commit(); reader.BeginRead(); updater.Commit(); updater.BeginUpdate(); reader.ForceDatabaseCacheValidation(); // we now validate on BeginRead so to make this test pass, we need to add this call after updater commit. } Database db2 = reader.OpenDatabase(dbNum); db = updater.OpenDatabase(dbNum); for (int i = 25; i < 50; i++) { foreach (Page page in db) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i); Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true); } } updater.Commit(); updater.BeginUpdate(); foreach (Page page in db2) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i + 1); Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false); } } reader.ClearPageCache(); // required or else we will use cached page and Assert (see line above) will fail System.GC.Collect(); // force weak referenced pages to be garbage collected (again to avoid Assert failure) } reader.Commit(); updater.DeleteDatabase(db); updater.Commit(); } finally { updater.Dispose(); reader.Dispose(); } }
[Repeat(3)] // remove when propagtion of optimistic locking flag is done to slave database locations TO DO (issue caused by CopyAllDatabasdesTo that uses pessimistic locking) public void multipleServersOK() { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginRead(); foreach (DatabaseLocation loc in session.DatabaseLocations) { Console.WriteLine(loc.ToStringDetails(session, false)); } session.Commit(); } using (ServerClientSession session = new ServerClientSession(systemDir, systemHost)) { session.SetTraceDbActivity(0); DatabaseLocation localLocation = new DatabaseLocation(systemHost, location2Dir, 10000, 20000, session, PageInfo.compressionKind.LZ4, 0); Placement place = new Placement(10000, 2); session.BeginUpdate(); foreach (DatabaseLocation loc in session.DatabaseLocations) { Console.WriteLine(loc.ToStringDetails(session, false)); } Console.WriteLine(); session.NewLocation(localLocation); foreach (DatabaseLocation loc in session.DatabaseLocations) { Console.WriteLine(loc.ToStringDetails(session, false)); } Man aMan = null; Woman aWoman = null; for (int j = 1; j <= 5; j++) { aMan = new Man(null, aMan, DateTime.UtcNow); aMan.Persist(place, session); aWoman = new Woman(aMan, aWoman); aWoman.Persist(place, session); aMan.m_spouse = new WeakIOptimizedPersistableReference <VelocityDbSchema.Person>(aWoman); if (j % 1000 == 0) { session.FlushUpdates(); } } localLocation = new DatabaseLocation(systemHost2, systemDir, 20001, 30000, session, PageInfo.compressionKind.LZ4, 0); session.NewLocation(localLocation); foreach (DatabaseLocation loc in session.DatabaseLocations) { Console.WriteLine(loc.ToStringDetails(session, false)); } place = new Placement(20001); //localDatabase = session.NewDatabase(20001, localLocation); for (int j = 1; j <= 5; j++) { aMan = new Man(null, aMan, DateTime.UtcNow); aMan.Persist(place, session); aWoman = new Woman(aMan, aWoman); aWoman.Persist(place, session); aMan.m_spouse = new WeakIOptimizedPersistableReference <VelocityDbSchema.Person>(aWoman); if (j % 1000 == 0) { session.FlushUpdates(); } } DatabaseLocation serverLocation = new DatabaseLocation(systemHost2, location2Dir, 30001, 40000, session, PageInfo.compressionKind.LZ4, 0); session.NewLocation(serverLocation); foreach (DatabaseLocation loc in session.DatabaseLocations) { Console.WriteLine(loc.ToStringDetails(session, false)); } place = new Placement(30001); for (int j = 1; j <= 5; j++) { aMan = new Man(null, aMan, DateTime.UtcNow); aMan.Persist(place, session); aWoman = new Woman(aMan, aWoman); aWoman.Persist(place, session); aMan.m_spouse = new WeakIOptimizedPersistableReference <VelocityDbSchema.Person>(aWoman); if (j % 1000 == 0) { session.FlushUpdates(); } } localLocation = new DatabaseLocation(systemHost3, systemDir, 40001, 50000, session, PageInfo.compressionKind.None, 0); session.NewLocation(localLocation); place = new Placement(40001); //localDatabase = session.NewDatabase(20001, localLocation); for (int j = 1; j <= 5; j++) { aMan = new Man(null, aMan, DateTime.UtcNow); aMan.Persist(place, session); aWoman = new Woman(aMan, aWoman); aWoman.Persist(place, session); aMan.m_spouse = new WeakIOptimizedPersistableReference <VelocityDbSchema.Person>(aWoman); if (j % 1000 == 0) { session.FlushUpdates(); } } session.Commit(); } using (ServerClientSession session = new ServerClientSession(systemDir, systemHost)) { session.CopyAllDatabasesTo(copyDir); using (SessionNoServer copySession = new SessionNoServer(copyDir)) { copySession.Verify(); } } using (ServerClientSession session = new ServerClientSession(systemDir, systemHost, 2000, false)) // TO DO, change back to use optimistic locking { //session.SetTraceDbActivity(0); session.BeginUpdate(); Database db = session.OpenDatabase(10000); session.DeleteDatabase(db); db = session.OpenDatabase(20001); session.DeleteDatabase(db); db = session.OpenDatabase(30001); session.DeleteDatabase(db); db = session.OpenDatabase(40001); session.DeleteDatabase(db); session.Commit(); Directory.Delete(copyDir, true); } System.GC.Collect(); System.GC.WaitForPendingFinalizers(); using (ServerClientSession session = new ServerClientSession(systemDir, systemHost)) { Assert.True(session.OptimisticLocking); } }
public void fCreateDatabasesPreSizeServer() { Database database; using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginUpdate(); for (uint i = 50000100; i < 50000200; i++) { database = session.NewDatabase(i, i - 50000100, "myServerSetDbName"); Assert.NotNull(database); } session.Commit(); } using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginUpdate(); for (uint i = 50000000; i < 50000200; i++) { database = session.OpenDatabase(i); Assert.NotNull(database); } session.Commit(); } }
public void ServerPageFlush() { using (ServerClientSession session = new ServerClientSession(systemDir, systemHost)) { //DatabaseLocation location = new DatabaseLocation(systemHost, location2Dir, 700, UInt32.MaxValue, session, false, PageInfo.encryptionKind.noEncryption); Placement place = new Placement(789, 1, 1, 1); //session.SetTraceAllDbActivity(); session.BeginUpdate(); session.RegisterClass(typeof(ObjWithArray)); // avoid lock failure by registrty ahead of running parallell sessions. session.RegisterClass(typeof(Person)); // avoid lock failure by registrty ahead of running parallell sessions. session.RegisterClass(typeof(VelocityDbSchema.Samples.AllSupportedSample.Pet)); // avoid lock failure by registrty ahead of running parallell sessions. session.RegisterClass(typeof(VelocityDbList <WeakIOptimizedPersistableReference <Person> >)); // avoid lock failure by registrty ahead of running parallell sessions. // session.NewLocation(location); session.Commit(); session.BeginUpdate(); for (int i = 0; i < 4000; i++) { ObjWithArray person = new ObjWithArray(i * 10); person.Persist(place, session); } session.FlushUpdates(); for (int i = 0; i < 1000; i++) { ObjWithArray person = new ObjWithArray(i); person.Persist(place, session); } using (ServerClientSession session2 = new ServerClientSession(systemDir, systemHost)) { Placement place2 = new Placement(7891, 1, 1, 1); session2.BeginUpdate(); for (int i = 0; i < 1000; i++) { ObjWithArray person = new ObjWithArray(i); person.Persist(place2, session2); } session2.FlushUpdates(); for (int i = 0; i < 1000; i++) { ObjWithArray person = new ObjWithArray(i); person.Persist(place2, session2); } session2.Commit(); } using (ServerClientSession session2 = new ServerClientSession(systemDir, systemHost)) { Placement place2 = new Placement(7894, 1, 1, 1); session2.BeginUpdate(); for (int i = 0; i < 5000; i++) { ObjWithArray person = new ObjWithArray(i); person.Persist(place2, session2); } session2.FlushUpdates(); for (int i = 0; i < 1000; i++) { ObjWithArray person = new ObjWithArray(i); person.Persist(place2, session2); } session2.Commit(); } using (ServerClientSession session2 = new ServerClientSession(systemDir, systemHost)) { Placement place2 = new Placement(7897, 1, 1, 1); session2.BeginUpdate(); for (int i = 0; i < 5000; i++) { ObjWithArray person = new ObjWithArray(i); person.Persist(place2, session2); } session2.FlushUpdates(); for (int i = 0; i < 1000; i++) { ObjWithArray person = new ObjWithArray(i); person.Persist(place2, session2); } using (ServerClientSession session3 = new ServerClientSession(systemDir, systemHost)) { Placement place3 = new Placement(7900, 1, 1, 1); session3.BeginUpdate(); for (int i = 0; i < 1000; i++) { ObjWithArray person = new ObjWithArray(i); person.Persist(place3, session3); } session3.FlushUpdates(); for (int i = 0; i < 1000; i++) { ObjWithArray person = new ObjWithArray(i); person.Persist(place3, session3); } session.Commit(); session2.Commit(); session3.Commit(); } } } }
public void PagesWritten() { using (ServerClientSession session = new ServerClientSession(systemDir, systemHost)) { Placement place = new Placement(789); session.BeginUpdate(); session.RegisterClass(typeof(Person)); session.RegisterClass(typeof(VelocityDbList <WeakIOptimizedPersistableReference <Person> >)); session.RegisterClass(typeof(VelocityDbSchema.Samples.AllSupportedSample.Pet)); session.RegisterClass(typeof(System.Guid)); session.RegisterClass(typeof(AutoPlacement)); session.Commit(); session.BeginUpdate(); Person person = new Person(); person.m_friends.Persist(place, session); person.Persist(place, session); session.FlushUpdates(); person = new Person(); person.Persist(place, session); using (ServerClientSession session2 = new ServerClientSession(systemDir, systemHost)) { Placement place2 = new Placement(7891); session2.BeginUpdate(); Person person2 = new Person(); person2.m_friends.Persist(place2, session2); person2.Persist(place2, session2); session2.FlushUpdates(); person2 = new Person(); person2.Persist(place2, session2); session2.Commit(); } using (ServerClientSession session2 = new ServerClientSession(systemDir, systemHost)) { Placement place2 = new Placement(7892); session2.BeginUpdate(); Person person2 = new Person(); person2.m_friends.Persist(place2, session2); person2.Persist(place2, session2); session2.FlushUpdates(); person2 = new Person(); person2.m_friends.Persist(place2, session2); person2.Persist(place2, session2); session2.Commit(); } using (ServerClientSession session2 = new ServerClientSession(systemDir, systemHost)) { Placement place2 = new Placement(7893); session2.BeginUpdate(); Person person2 = new Person(); person2.m_friends.Persist(place2, session2); person2.Persist(place2, session2); session2.FlushUpdates(); person2 = new Person(); person2.Persist(place2, session2); using (ServerClientSession session3 = new ServerClientSession(systemDir, systemHost)) { Placement place3 = new Placement(7894); session3.BeginUpdate(); Person person3 = new Person(); person3.m_friends.Persist(place3, session3); person3.Persist(place3, session3); session3.FlushUpdates(); person3 = new Person(); person3.m_friends.Persist(place3, session3); person3.Persist(place3, session3); session.Commit(); session2.Commit(); session3.Commit(); } } } }
public void HighAvalailabiltyByReplication() { var alternateSystemBoot = new List <ReplicaInfo> { new ReplicaInfo { Path = "Replica1" }, new ReplicaInfo { Path = "Replica2" } }; var p1 = SessionBase.BaseDatabasePath + "/Replica1"; var p2 = SessionBase.BaseDatabasePath + "/Replica2"; var p3 = SessionBase.BaseDatabasePath + "/Replica3"; var p3remote = $"\\{s_systemHost2}/databases/Replica3"; if (Directory.Exists(p1)) { Directory.Delete(p1, true); } if (Directory.Exists(p2)) { Directory.Delete(p2, true); } if (Directory.Exists(p3)) { Directory.Delete(p3, true); } if (Directory.Exists(p3remote)) { Directory.Delete(p3remote, true); } using (var session = new ServerClientSession(alternateSystemBoot)) { session.BeginUpdate(); for (int i = 0; i < 100; i++) { var s = i.ToString(); session.Persist(s); } session.Commit(); } alternateSystemBoot = new List <ReplicaInfo> { new ReplicaInfo { Path = "Replica1" }, new ReplicaInfo { Path = "Replica2" }, new ReplicaInfo { Path = "Replica3", Host = s_systemHost2 } }; using (var session = new ServerClientSession(alternateSystemBoot)) { session.BeginUpdate(); for (int i = 0; i < 100; i++) { var s = i.ToString(); session.Persist(s); } session.Commit(); } using (var session = new ServerClientSession(alternateSystemBoot)) { session.BeginUpdate(); for (int i = 0; i < 10; i++) { var s = i.ToString(); session.Persist(s); } if (Directory.Exists(p2)) { Directory.Delete(p2, true); } session.Commit(); } using (var session = new ServerClientSession(alternateSystemBoot)) { session.BeginRead(); foreach (var s in session.AllObjects <string>()) { Console.WriteLine(s); } session.Commit(); } using (var session = new ServerClientSession(alternateSystemBoot)) { session.BeginUpdate(); for (int i = 0; i < 10; i++) { var s = i.ToString(); session.Persist(s); if (Directory.Exists(p2)) { Directory.Delete(p2, true); } } session.Commit(); } using (var session = new ServerClientSession(alternateSystemBoot)) { session.BeginRead(); foreach (var s in session.AllObjects <string>()) { Console.WriteLine(s); } session.Commit(); } using (var session = new SessionNoServer("Replica1")) { session.Verify(); } using (var session = new SessionNoServer("Replica2")) { session.Verify(); } using (var session = new ServerClientSession("Replica3", s_systemHost2)) { session.Verify(); } }
public void multipleServersOKCleanup() { using (ServerClientSession session = new ServerClientSession(systemDir, systemHost, 2000, false)) // TO DO, change back to use optimistic locking { //session.SetTraceDbActivity(0); session.BeginUpdate(); Database db = session.OpenDatabase(10000, true, false); if (db != null) session.DeleteDatabase(db); db = session.OpenDatabase(20001, true, false); if (db != null) session.DeleteDatabase(db); db = session.OpenDatabase(30001, true, false); if (db != null) session.DeleteDatabase(db); db = session.OpenDatabase(40001, true, false); if (db != null) session.DeleteDatabase(db); session.Commit(); if (Directory.Exists(copyDir)) Directory.Delete(copyDir, true); } System.GC.Collect(); System.GC.WaitForPendingFinalizers(); using (ServerClientSession session = new ServerClientSession(systemDir, systemHost)) { Assert.True(session.OptimisticLocking); } }
public void DeleteDefaultLocation() { using (ServerClientSession session = new ServerClientSession(s_systemDir, systemHost, 1000, true, inMemoryOnly)) { session.BeginUpdate(); DatabaseLocation defaultLocation = session.DatabaseLocations.Default(); List<Database> dbList = session.OpenLocationDatabases(defaultLocation, true); foreach (Database db in dbList) if (db.DatabaseNumber > Database.InitialReservedDatabaseNumbers) session.DeleteDatabase(db); session.DeleteLocation(defaultLocation); session.Commit(); } }
public void DeleteBackupLocation() { using (ServerClientSession session = new ServerClientSession(s_systemDir, systemHost, 1000, true, inMemoryOnly)) { session.BeginUpdate(); DatabaseLocation backupLocation = session.DatabaseLocations.LocationForDb(backupLocationStartDbNum); List<Database> dbList = session.OpenLocationDatabases(backupLocation, true); foreach (Database db in dbList) session.DeleteDatabase(db); session.DeleteLocation(backupLocation); session.Commit(); } }
public void multipleServersInvalid() { Assert.Throws<InvalidChangeOfDefaultLocationException>(() => { using (ServerClientSession session = new ServerClientSession(systemDir)) { session.SetTraceDbActivity(2); try { DatabaseLocation localLocation = new DatabaseLocation(systemHost, location2Dir, 10000, 20000, session, PageInfo.compressionKind.LZ4, 0); Placement place = new Placement(10000, 2); session.BeginUpdate(); session.NewLocation(localLocation); Man aMan = null; Woman aWoman = null; for (int j = 1; j <= 5; j++) { aMan = new Man(null, aMan, DateTime.UtcNow); aMan.Persist(place, session); aWoman = new Woman(aMan, aWoman); aWoman.Persist(place, session); aMan.m_spouse = new WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman); if (j % 1000 == 0) { session.FlushUpdates(); } } localLocation = new DatabaseLocation(systemHost, systemDir, 20001, 30000, session, PageInfo.compressionKind.None, 0); session.NewLocation(localLocation); place = new Placement(20001); //localDatabase = session.NewDatabase(20001, localLocation); for (int j = 1; j <= 5; j++) { aMan = new Man(null, aMan, DateTime.UtcNow); aMan.Persist(place, session); aWoman = new Woman(aMan, aWoman); aWoman.Persist(place, session); aMan.m_spouse = new WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman); if (j % 1000 == 0) { session.FlushUpdates(); } } DatabaseLocation serverLocation = new DatabaseLocation(systemHost2, location2Dir, 30001, 40000, session, PageInfo.compressionKind.LZ4, 0); session.NewLocation(serverLocation); place = new Placement(30001); for (int j = 1; j <= 5; j++) { aMan = new Man(null, aMan, DateTime.UtcNow); aMan.Persist(place, session); aWoman = new Woman(aMan, aWoman); aWoman.Persist(place, session); aMan.m_spouse = new WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman); if (j % 1000 == 0) { session.FlushUpdates(); } } session.Commit(); } finally { //session.Close(); } } }); }
public void SingleServerReaderSingleServerUpdater1() { ServerClientSession updater = new ServerClientSession(systemDir); ServerClientSession reader = new ServerClientSession(systemDir); const UInt32 dbNum = 345; try { updater.BeginUpdate(); Man man; Placement place = new Placement(dbNum, 1, 1, 2); for (int i = 0; i < 100; i++) { man = new Man(); man.Persist(place, updater); } updater.Commit(); reader.BeginRead(); Database db = reader.OpenDatabase(dbNum); foreach (Page page in db) { Assert.True(page.PageInfo.VersionNumber == 1); } reader.Commit(); updater.BeginUpdate(); reader.BeginRead(); for (int i = 1; i < 25; i++) { db = reader.OpenDatabase(dbNum); foreach (Page page in db) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i); Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false); Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true); } } reader.Commit(); reader.BeginRead(); updater.Commit(); updater.BeginUpdate(); reader.ForceDatabaseCacheValidation(); // we now validate on BeginRead so to make this test pass, we need to add this call after updater commit. } Database db2 = reader.OpenDatabase(dbNum); db = updater.OpenDatabase(dbNum); for (int i = 25; i < 50; i++) { foreach (Page page in db) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i); Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true); } } updater.Commit(); updater.BeginUpdate(); foreach (Page page in db2) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i + 1); Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false); } } reader.ClearPageCache(); // required or else we will use cached page and Assert (see line above) will fail System.GC.Collect(); // force weak referenced pages to be garbage collected (again to avoid Assert failure) } reader.Commit(); updater.DeleteDatabase(db); updater.Commit(); } finally { updater.Dispose(); reader.Dispose(); } }
public void serverSessionOverhead(int numberOfSessions) { for (int i = 0; i < numberOfSessions; i++) { using (ServerClientSession session = new ServerClientSession(systemDir2, systemHost3)) { session.BeginUpdate(); session.Commit(); } } }
public void RestoreToBackupServer() { using (ServerClientSession session = new ServerClientSession(s_systemDir, systemHost)) { session.ClearServerCache(); // normally don't use this function but use it here to simulate a server going down and restarting } using (ServerClientSession session = new ServerClientSession(s_systemDir, backupHost, 1000, true, inMemoryOnly)) { session.BeginUpdate(); DatabaseLocation backupLocation = new DatabaseLocation(backupHost, backupDir, backupLocationStartDbNum, UInt32.MaxValue, session, PageInfo.compressionKind.LZ4, PageInfo.encryptionKind.noEncryption, true, session.DatabaseLocations.Default()); session.RestoreFrom(backupLocation, DateTime.MaxValue); session.Commit(false, true); } }
public static void CreateUser() { using (ServerClientSession session = new ServerClientSession(systemDir, systemHost)) { session.BeginUpdate(); Graph g = Graph.Open(session); VertexType movieType = g.FindVertexType("MOVIE"); PropertyType movieTitleType = movieType.FindProperty("TITLE"); PropertyType movieYearType = movieType.FindProperty("YEAR"); for (int i = 1; i < 50; i++) { Vertex mVickyCB = movieType.NewVertex(); mVickyCB.SetProperty(movieTitleType, "Vicky Cristina Barcelona" + i); mVickyCB.SetProperty(movieYearType, (int)(2008 + i)); session.Commit(); session.BeginUpdate(); Thread.Sleep(1000); } } }
public void CreateMoreDataWithBackupServer() { int loops = 30000; UInt16 objectsPerPage = 350; UInt16 pagesPerDatabase = 65000; int j; using (ServerClientSession session = new ServerClientSession(systemDir, Dns.GetHostName())) { Placement place = new Placement(11, 1, 1, objectsPerPage, pagesPerDatabase); Man aMan = null; Woman aWoman = null; session.BeginUpdate(); for (j = 1; j <= loops; j++) { aMan = new Man(null, aMan, DateTime.UtcNow); aMan.Persist(place, session); aWoman = new Woman(aMan, aWoman); aWoman.Persist(place, session); aMan.m_spouse = new WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman); if (j % 1000000 == 0) Console.WriteLine("Loop # " + j); } UInt64 id = aWoman.Id; Console.WriteLine("Commit, done Loop # " + j); session.Commit(); } }
public void CachedSessionTest() { ServerClientSession lSession = GetCachedSession(); //lets simulate that we did some prior work, return the session and get it again ReturnSessionToCache(lSession); lSession = GetCachedSession(); TestClass lTestClass = new TestClass(); lTestClass.SomeIntVar = 123; lTestClass.SomeStringVar = "test"; UInt64 id = lTestClass.Persist(lSession, lTestClass); var c = new Class_A(); UInt64 id2 = lSession.Persist(c); Class_B class_b = new Class_B(); class_b.IntField = 11; class_b.StringField = "sss"; Class_A class_a = new Class_A(); class_a.string_field = "xxx"; class_a.b_field = class_b; UInt64 id3 = lSession.Persist(class_a); lSession.Commit(); //return to cache, get it again and query the object //as this test is to verify it does not hang we do it in separate thread and kill after timeout ReturnSessionToCache(lSession); lSession = GetCachedSession(); lSession.Abort(); lSession.BeginUpdate(); Class_A cA = lSession.Open <Class_A>(id2); cA = lSession.Open <Class_A>(id3); lTestClass = lSession.Open <TestClass>(id); Assert.NotNull(lTestClass.GeoCord); Assert.NotNull(lTestClass.StoredStructInObjectField); lTestClass.SomeIntVar = 1234; lTestClass.SomeStringVar = "test2"; lTestClass.Persist(lSession, lTestClass); lSession.Commit(); //return to cache, get it again and query the object //as this test is to verify it does not hang we do it in separate thread and kill after timeout ReturnSessionToCache(lSession); lSession = GetCachedSession(); counter = (int)lSession.AllObjects <TestClass>(true, false).Count(); ReturnSessionToCache(lSession); Thread lThread = new Thread(new ThreadStart(() => { lSession = GetCachedSession(); counter = (int)lSession.AllObjects <TestClass>(true, false).Count(); ReturnSessionToCache(lSession); })); lThread.Start(); lEvent.WaitOne(5000); if (lThread.IsAlive) { lThread.Abort(); } Assert.AreNotEqual(0, counter, "Invalid number of objects retrieved"); }
public void multipleServersInvalid() { Assert.Throws <InvalidChangeOfDefaultLocationException>(() => { using (ServerClientSession session = new ServerClientSession(systemDir)) { session.SetTraceDbActivity(2); try { DatabaseLocation localLocation = new DatabaseLocation(systemHost, location2Dir, 10000, 20000, session, PageInfo.compressionKind.LZ4, 0); Placement place = new Placement(10000, 2); session.BeginUpdate(); session.NewLocation(localLocation); Man aMan = null; Woman aWoman = null; for (int j = 1; j <= 5; j++) { aMan = new Man(null, aMan, DateTime.UtcNow); aMan.Persist(place, session); aWoman = new Woman(aMan, aWoman); aWoman.Persist(place, session); aMan.m_spouse = new WeakIOptimizedPersistableReference <VelocityDbSchema.Person>(aWoman); if (j % 1000 == 0) { session.FlushUpdates(); } } localLocation = new DatabaseLocation(systemHost, systemDir, 20001, 30000, session, PageInfo.compressionKind.None, 0); session.NewLocation(localLocation); place = new Placement(20001); //localDatabase = session.NewDatabase(20001, localLocation); for (int j = 1; j <= 5; j++) { aMan = new Man(null, aMan, DateTime.UtcNow); aMan.Persist(place, session); aWoman = new Woman(aMan, aWoman); aWoman.Persist(place, session); aMan.m_spouse = new WeakIOptimizedPersistableReference <VelocityDbSchema.Person>(aWoman); if (j % 1000 == 0) { session.FlushUpdates(); } } DatabaseLocation serverLocation = new DatabaseLocation(systemHost2, location2Dir, 30001, 40000, session, PageInfo.compressionKind.LZ4, 0); session.NewLocation(serverLocation); place = new Placement(30001); for (int j = 1; j <= 5; j++) { aMan = new Man(null, aMan, DateTime.UtcNow); aMan.Persist(place, session); aWoman = new Woman(aMan, aWoman); aWoman.Persist(place, session); aMan.m_spouse = new WeakIOptimizedPersistableReference <VelocityDbSchema.Person>(aWoman); if (j % 1000 == 0) { session.FlushUpdates(); } } session.Commit(); } finally { //session.Close(); } } }); }
public void RestoreAllViaServer() { using (ServerClientSession session = new ServerClientSession(systemDir, null, 2000, false)) // don't use optimistic locking for restore { session.BeginUpdate(); DatabaseLocation backupLocation = new DatabaseLocation(Dns.GetHostName(), backupDir, backupLocationStartDbNum, UInt32.MaxValue, session, PageInfo.compressionKind.None, PageInfo.encryptionKind.noEncryption, true, session.DatabaseLocations.Default()); session.RestoreFrom(backupLocation, DateTime.UtcNow); session.Commit(false, true); } }
public void SimpleApiServer() { long ssn = 555555; UInt16 age = 1; VelocityDbSchema.Person mats; Placement place; using (ServerClientSession session = new ServerClientSession(systemDir)) { // skip delete database since it invalidates indices session.BeginUpdate(); Database db = session.OpenDatabase(10, true, false); if (db != null) { session.DeleteDatabase(db); } session.Commit(); session.BeginUpdate(); place = new Placement(10, 2, 1, 1, 10); DateTime birthday = new DateTime(1960, 6, 13); mats = new Man("Mats", "Persson", age++, ssn++, birthday); mats.Persist(place, session); session.Commit(); session.ClearServerCache(); } UInt64 mOid1 = Oid.Encode(10, 2, 1); using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginUpdate(); UInt32 dbNum = Oid.DatabaseNumber(mOid1); mats = (VelocityDbSchema.Person)session.Open(mOid1); Woman kinga = null; mats = new Man("Mats", "Persson", age++, ssn++, new DateTime(1960, 6, 13)); Cat cat = new Cat("Boze", 8); mats.m_pets.Add(cat); Bird bird = new Bird("Pippi", 1); cat.friends.Add(bird); mats.Persist(place, session); kinga = new Woman("Kinga", "Persson", age, ssn, mats, mats); kinga.Persist(place, session); VelocityDbSchema.Person robin = new VelocityDbSchema.Person("Robin", "Persson", 13, 1, mats, null); robin.Persist(place, session); mOid1 = mats.Id; mats = null; mats = (VelocityDbSchema.Person)session.Open(mOid1); session.Commit(); session.ClearServerCache(); } using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginUpdate(); mats = (VelocityDbSchema.Person)session.Open(mOid1); session.Commit(); session.ClearServerCache(); } using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginRead(); ulong mOid2 = mats.Id; mats = (VelocityDbSchema.Person)session.Open(mOid2); session.Commit(); session.ClearServerCache(); } }
public void gDeleteDatabasesServer() { Database database; using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginUpdate(); for (uint i = 50000000; i < 50000100; i++) { database = session.OpenDatabase(i); session.DeleteDatabase(database); } session.Commit(); } }
public void test() { ServerClientSession VelocityServerSession = new ServerClientSession(systemDir, "localhost"); Woman TmpSynchronizationData = new Woman();//APSSynchData TmpSynchronizationData = default(APSSynchData); // APSSynchData(); //TmpSynchronizationData.SyncedElections = new VelocityDbList<Man>(); VelocityServerSession.BeginUpdate(); TmpSynchronizationData.Persist(VelocityServerSession, TmpSynchronizationData); VelocityServerSession.Commit(); //SaveToDisk("4.odb", DatabasePath + "\\4.odb"); VelocityServerSession.BeginUpdate(); }
[Repeat(3)] // remove when propagation of optimistic locking flag is done to slave database locations TO DO (issue caused by CopyAllDatabasdesTo that uses pessimistic locking) public void multipleServersOK() { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginRead(); foreach (DatabaseLocation loc in session.DatabaseLocations) Console.WriteLine(loc.ToStringDetails(session, false)); session.Commit(); } using (ServerClientSession session = new ServerClientSession(systemDir, systemHost)) { session.SetTraceDbActivity(0); DatabaseLocation localLocation = new DatabaseLocation(systemHost, location2Dir, 10000, 20000, session, PageInfo.compressionKind.LZ4, 0); Placement place = new Placement(10000, 2); session.BeginUpdate(); foreach (DatabaseLocation loc in session.DatabaseLocations) Console.WriteLine(loc.ToStringDetails(session, false)); Console.WriteLine(); session.NewLocation(localLocation); foreach (DatabaseLocation loc in session.DatabaseLocations) Console.WriteLine(loc.ToStringDetails(session, false)); Man aMan = null; Woman aWoman = null; for (int j = 1; j <= 5; j++) { aMan = new Man(null, aMan, DateTime.UtcNow); aMan.Persist(place, session); aWoman = new Woman(aMan, aWoman); aWoman.Persist(place, session); aMan.m_spouse = new WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman); if (j % 1000 == 0) { session.FlushUpdates(); } } localLocation = new DatabaseLocation(systemHost2, systemDir, 20001, 30000, session, PageInfo.compressionKind.LZ4, 0); session.NewLocation(localLocation); foreach (DatabaseLocation loc in session.DatabaseLocations) Console.WriteLine(loc.ToStringDetails(session, false)); place = new Placement(20001); //localDatabase = session.NewDatabase(20001, localLocation); for (int j = 1; j <= 5; j++) { aMan = new Man(null, aMan, DateTime.UtcNow); aMan.Persist(place, session); aWoman = new Woman(aMan, aWoman); aWoman.Persist(place, session); aMan.m_spouse = new WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman); if (j % 1000 == 0) { session.FlushUpdates(); } } DatabaseLocation serverLocation = new DatabaseLocation(systemHost2, location2Dir, 30001, 40000, session, PageInfo.compressionKind.LZ4, 0); session.NewLocation(serverLocation); foreach (DatabaseLocation loc in session.DatabaseLocations) Console.WriteLine(loc.ToStringDetails(session, false)); place = new Placement(30001); for (int j = 1; j <= 5; j++) { aMan = new Man(null, aMan, DateTime.UtcNow); aMan.Persist(place, session); aWoman = new Woman(aMan, aWoman); aWoman.Persist(place, session); aMan.m_spouse = new WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman); if (j % 1000 == 0) { session.FlushUpdates(); } } localLocation = new DatabaseLocation(systemHost3, systemDir, 40001, 50000, session, PageInfo.compressionKind.None, 0); session.NewLocation(localLocation); place = new Placement(40001); //localDatabase = session.NewDatabase(20001, localLocation); for (int j = 1; j <= 5; j++) { aMan = new Man(null, aMan, DateTime.UtcNow); aMan.Persist(place, session); aWoman = new Woman(aMan, aWoman); aWoman.Persist(place, session); aMan.m_spouse = new WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman); if (j % 1000 == 0) { session.FlushUpdates(); } } session.Commit(); } using (ServerClientSession session = new ServerClientSession(systemDir, systemHost)) { session.CopyAllDatabasesTo(copyDir); using (SessionNoServer copySession = new SessionNoServer(copyDir)) { copySession.Verify(); } } using (ServerClientSession session = new ServerClientSession(systemDir, systemHost, 2000, false)) // TO DO, change back to use optimistic locking { //session.SetTraceDbActivity(0); session.BeginUpdate(); Database db = session.OpenDatabase(10000); session.DeleteDatabase(db); db = session.OpenDatabase(20001); session.DeleteDatabase(db); db = session.OpenDatabase(30001); session.DeleteDatabase(db); db = session.OpenDatabase(40001); session.DeleteDatabase(db); session.Commit(); Directory.Delete(copyDir, true); } System.GC.Collect(); System.GC.WaitForPendingFinalizers(); using (ServerClientSession session = new ServerClientSession(systemDir, systemHost)) { Assert.True(session.OptimisticLocking); } }