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() { 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 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 static void WatchUser() { using (ServerClientSession session = new ServerClientSession(systemDir, systemHost, 1000, true, false)) { session.BeginRead(); session.SubscribeToChanges(typeof(Vertex)); Graph g = Graph.Open(session); session.Commit(); Thread.Sleep(5000); 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(1000); } 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)); } session.Commit(); Thread.Sleep(2000); } } }
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 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(); } }
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 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 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(); } }
/// <summary> /// Tests the caching and re using of sessiosn to increase perfomance by avoding /// creating new sessions for each client request /// </summary> // [Test] 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"; 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 therad and kill after timeout ReturnSessionToCache(lSession); Thread lThread = new Thread(new ThreadStart(() => { lSession = GetCachedSession(); counter = lSession.AllObjects <TestClass>(true, false).Count(); ReturnSessionToCache(lSession); })); lThread.Start(); lEvent.WaitOne(5000); if (lThread.IsAlive) { lThread.Abort(); } Assert.AreNotEqual(0, counter, "Invalid nr of objects retreived"); }
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(); } }
public void dServerIterateDatabases() { using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginRead(); session.OpenAllDatabases(); session.Commit(); } }
public void b2ServerIterateDatabases() { using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginRead(); session.OpenAllDatabases(); 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 bServerIterateDatabases() { Database database; using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginRead(); for (uint i = 50000000; i < 50001000; i++) database = session.OpenDatabase(i); 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 OneMillionFindSingleRecordInTheMiddleServer() { using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginRead(); var result = (from ComputerFileData computerFileData in session.AllObjects <ComputerFileData>() where computerFileData.FileID == 500000 select computerFileData).First(); session.Commit(); } }
public void serverSessionOverhead(int numberOfSessions) { for (int i = 0; i < numberOfSessions; i++) { using (ServerClientSession session = new ServerClientSession(systemDir2, systemHost3)) { session.BeginUpdate(); 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 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 bServerIterateDatabases() { Database database; using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginRead(); for (uint i = 50000000; i < 50001000; i++) { database = session.OpenDatabase(i); } 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 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 ReadSomeData() { int ct = 0; using (ServerClientSession session = new ServerClientSession(s_systemDir, systemHost, 1000, true, inMemoryOnly)) { session.BeginRead(); foreach (Man man in session.AllObjects <Man>()) { ct++; } Console.WriteLine("Commit, number of Men found: " + ct); 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(); } }
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 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 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 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 ReadSomeData() { int ct = 0; using (ServerClientSession session = new ServerClientSession(s_systemDir, systemHost, 1000, true, inMemoryOnly)) { session.BeginRead(); foreach (Man man in session.AllObjects<Man>()) { ct++; } Console.WriteLine("Commit, number of Men found: " + ct); 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 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 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(); } }
public static void WatchUser() { using (ServerClientSession session = new ServerClientSession(systemDir, systemHost, 1000, true, false)) { session.BeginRead(); session.SubscribeToChanges(typeof(Vertex)); Graph g = Graph.Open(session); session.Commit(); Thread.Sleep(5000); 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(1000); } 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)); } session.Commit(); Thread.Sleep(2000); } } }
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 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(); } }
[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); } }
static readonly string systemDir = "VelocityGraphSample"; // appended to SessionBase.BaseDatabasePath static void Main(string[] args) { using (SessionNoServer session = new SessionNoServer(systemDir)) { if (Directory.Exists(session.SystemDirectory)) Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases. Console.WriteLine("Running with databases in directory: " + session.SystemDirectory); session.BeginUpdate(); Graph g = new Graph(session); session.Persist(g); // SCHEMA // Add a node type for the movies, with a unique identifier and two indexed Propertys VertexType movieType = g.NewVertexType("MOVIE"); PropertyType movieTitleType = g.NewVertexProperty(movieType, "TITLE", DataType.String, PropertyKind.Indexed); PropertyType movieYearType = g.NewVertexProperty(movieType, "YEAR", DataType.Integer, PropertyKind.Indexed); // Add a node type for the people, with a unique identifier and an indexed Property VertexType peopleType = g.NewVertexType("PEOPLE"); PropertyType peopleNameType = g.NewVertexProperty(peopleType, "NAME", DataType.String, PropertyKind.Indexed); // Add an undirected edge type with a Property for the cast of a movie EdgeType castType = g.NewEdgeType("CAST", false); PropertyType castCharacterType = g.NewEdgeProperty(castType, "CHARACTER", DataType.String, PropertyKind.Indexed); // Add a directed edge type restricted to go from people to movie for the director of a movie EdgeType directsType = g.NewEdgeType("DIRECTS", true, peopleType, movieType); // DATA // Add some MOVIE nodes Vertex mLostInTranslation = movieType.NewVertex(); mLostInTranslation.SetProperty(movieTitleType, "Lost in Translation"); mLostInTranslation.SetProperty(movieYearType, (int)2003); Vertex mVickyCB = movieType.NewVertex(); mVickyCB.SetProperty(movieTitleType, "Vicky Cristina Barcelona"); mVickyCB.SetProperty(movieYearType, (int)2008); Vertex mManhattan = movieType.NewVertex(); mManhattan.SetProperty(movieTitleType, "Manhattan"); mManhattan.SetProperty(movieYearType, (int)1979); // Add some PEOPLE nodes Vertex pScarlett = peopleType.NewVertex(); pScarlett.SetProperty(peopleNameType, "Scarlett Johansson"); Vertex pBill = peopleType.NewVertex(); pBill.SetProperty(peopleNameType, "Bill Murray"); Vertex pSofia = peopleType.NewVertex(); pSofia.SetProperty(peopleNameType, "Sofia Coppola"); Vertex pWoody = peopleType.NewVertex(); pWoody.SetProperty(peopleNameType, "Woody Allen"); Vertex pPenelope = peopleType.NewVertex(); pPenelope.SetProperty(peopleNameType, "Penélope Cruz"); Vertex pDiane = peopleType.NewVertex(); pDiane.SetProperty(peopleNameType, "Diane Keaton"); // Add some CAST edges Edge anEdge; anEdge = g.NewEdge(castType, mLostInTranslation, pScarlett); anEdge.SetProperty(castCharacterType, "Charlotte"); anEdge = g.NewEdge(castType, mLostInTranslation, pBill); anEdge.SetProperty(castCharacterType, "Bob Harris"); anEdge = g.NewEdge(castType, mVickyCB, pScarlett); anEdge.SetProperty(castCharacterType, "Cristina"); anEdge = g.NewEdge(castType, mVickyCB, pPenelope); anEdge.SetProperty(castCharacterType, "Maria Elena"); anEdge = g.NewEdge(castType, mManhattan, pDiane); anEdge.SetProperty(castCharacterType, "Mary"); anEdge = g.NewEdge(castType, mManhattan, pWoody); anEdge.SetProperty(castCharacterType, "Isaac"); // Add some DIRECTS edges anEdge = g.NewEdge(directsType, pSofia, mLostInTranslation); anEdge = g.NewEdge(directsType, pWoody, mVickyCB); anEdge = g.NewEdge(directsType, pWoody, mManhattan); // QUERIES // Get the movies directed by Woody Allen Dictionary<Vertex, HashSet<Edge>> directedByWoody = pWoody.Traverse(directsType, Direction.Out); // Get the cast of the movies directed by Woody Allen Dictionary<Vertex, HashSet<Edge>> castDirectedByWoody = g.Traverse(directedByWoody.Keys.ToArray(), castType, Direction.Both); // Get the movies directed by Sofia Coppola Dictionary<Vertex, HashSet<Edge>> directedBySofia = pSofia.Traverse(directsType, Direction.Out); // Get the cast of the movies directed by Sofia Coppola Dictionary<Vertex, HashSet<Edge>> castDirectedBySofia = g.Traverse(directedBySofia.Keys.ToArray(), castType, Direction.Both); // We want to know the people that acted in movies directed by Woody AND in movies directed by Sofia. IEnumerable<Vertex> castFromBoth = castDirectedByWoody.Keys.Intersect(castDirectedBySofia.Keys); // Say hello to the people found foreach (Vertex person in castFromBoth) { object value = person.GetProperty(peopleNameType); System.Console.WriteLine("Hello " + value); } var billM = g.Traverse(directedBySofia.Keys.ToArray(), castType, Direction.Both).Keys.Where(vertex => vertex.GetProperty(peopleNameType).Equals("Bill Murray")); // Say hello to Bill Murray foreach (Vertex person in billM) { object value = person.GetProperty(peopleNameType); System.Console.WriteLine("Hello " + value); } session.Commit(); } using (ServerClientSession session = new ServerClientSession(systemDir, System.Net.Dns.GetHostName())) { session.BeginRead(); Graph g = Graph.Open(session); VertexType movieType = g.FindVertexType("MOVIE"); PropertyType movieTitleProperty = g.FindVertexProperty(movieType, "TITLE"); Vertex obj = g.FindVertex(movieTitleProperty, "Manhattan"); 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 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 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(); } }
[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); } }
public void OneMillionFindSingleRecordInTheMiddleServer() { using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginRead(); var result = (from ComputerFileData computerFileData in session.AllObjects<ComputerFileData>() where computerFileData.FileID == 500000 select computerFileData).First(); session.Commit(); } }