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()); } }
private void session2locking(object sender, RoutedEventArgs e) { if (session != null) { try { if (session[1].InTransaction == false) { if (session2server.IsChecked.Value) { session[1] = new ServerClientSession(systemDir, null, int.Parse(session2LockTimeout.Text), session2optimistic.IsChecked.Value); } else { session[1] = new SessionNoServer(systemDir, int.Parse(session2LockTimeout.Text), session2optimistic.IsChecked.Value); } } else { session2messages.Content = "Can only set OptimisticLocking attribute while not in a transaction"; } } catch (Exception ex) { session2messages.Content = ex.Message; } } }
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 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 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 = 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(); } }
/// <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"); }
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 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 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 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(); } }
void BtnOkClick(object pSender, RoutedEventArgs pEvents) { m_federationInfo.UsesServerClient = (bool)RadioServer.IsChecked; m_federationInfo.ClassesFilenames = (from ListViewItem lItem in AssemblyList.Items select(string) lItem.Content).ToArray(); m_federationInfo.DependencyFiles = (from ListViewItem lItem in DependencyList.Items select(string) lItem.Content).ToArray(); m_federationInfo.SystemDbsPath = DBDirTextBox.Text; m_federationInfo.HostName = HostTextBox.Text; m_federationInfo.UsePessimisticLocking = (bool)PessimisticBox.IsChecked; m_federationInfo.WindowsAuthentication = (bool)WindowsAuthenticationBox.IsChecked; bool createNew = (bool)CreateNewBox.IsChecked; if (createNew) { SessionBase session; if (m_federationInfo.UsesServerClient || (m_federationInfo.HostName.Length > 0 && m_federationInfo.HostName != Dns.GetHostName())) { session = new ServerClientSession(m_federationInfo.SystemDbsPath, m_federationInfo.HostName); } else { session = new SessionNoServer(m_federationInfo.SystemDbsPath); } session.BeginUpdate(); session.Commit(); } DialogResult = true; }
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 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 DatabaseVersion(bool standalone, UInt32 dbNumber) { SessionBase session; if (standalone) { session = new SessionNoServer(systemDir); } else { session = new ServerClientSession(systemDir); } session.BeginUpdate(); Placement place = new Placement(dbNumber); int i = 0; UInt64[] ids = new UInt64[10]; VelocityDbSchema.Samples.Sample1.Person person = new VelocityDbSchema.Samples.Sample1.Person("Bill" + i, "Gates", 56); person.Persist(place, session); ids[i++] = person.Id; Database db = session.OpenDatabase(dbNumber); Assert.AreEqual(0, db.PersistentVersion()); session.Commit(); Assert.AreEqual(1, db.PersistentVersion()); session.BeginUpdate(); Assert.AreEqual(1, db.PersistentVersion()); person = new VelocityDbSchema.Samples.Sample1.Person("Bill" + i, "Gates", 56); person.Persist(place, session); ids[i++] = person.Id; person = new VelocityDbSchema.Samples.Sample1.Person("Bill" + i, "Gates", 56); person.Persist(place, session); ids[i++] = person.Id; Assert.AreEqual(1, db.PersistentVersion()); session.Commit(); Assert.AreEqual(2, db.PersistentVersion()); session.BeginRead(); Assert.AreEqual(2, db.PersistentVersion()); session.Commit(); session.BeginUpdate(); person = new VelocityDbSchema.Samples.Sample1.Person("Bill" + i, "Gates", 56); person.Persist(place, session); ids[i++] = person.Id; session.Commit(); Assert.AreEqual(3, db.PersistentVersion()); session.BeginUpdate(); for (int j = 0; j < i; j++) { session.DeleteObject(ids[j]); } session.Commit(); Assert.AreEqual(4, db.PersistentVersion()); session.BeginRead(); Assert.AreEqual(4, db.PersistentVersion()); session.Commit(); session.BeginUpdate(); session.DeleteDatabase(db); session.Commit(); session.Dispose(); }
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> /// Returns a session to the cache.To be sure we have no transactiona ctive we abort in case /// the caller of this method did not commit or abort /// </summary> void ReturnSessionToCache(ServerClientSession pSession) { pSession.Abort(); lock (sessions) { sessions.Add(pSession); } }
/// <summary> /// Returns a session to the cache.To be sure we have no transactiona ctive we abort in case /// the caller of this method did not commit or abort /// </summary> void ReturnSessionToCache(ServerClientSession pSession) { pSession.Abort(); lock (sessions) { sessions.Add(pSession); } }
void VersionManagerTest(SessionBase sess) { VelocityDbSchema.Samples.Sample1.Person person; sess.BeginUpdate(); foreach (DatabaseLocation loc in sess.DatabaseLocations) { Console.WriteLine(loc.ToStringDetails(sess, false)); } Console.WriteLine(); var count = 10000; var vm = GetVersionManager(sess) ?? new VersionManager <VelocityDbSchema.Samples.Sample1.Person>(RecordType.Person); var startCount = vm.Count; var tw = new Stopwatch(); tw.Start(); for (int i = startCount; i < count + startCount; i++) { person = new VelocityDbSchema.Samples.Sample1.Person("Bill" + i, "Gates", 56); person.Persist(sess, person); vm.Add(new WeakIOptimizedPersistableReference <VelocityDbSchema.Samples.Sample1.Person>(person)); } vm.Persist(sess, vm); tw.Stop(); Console.WriteLine("{0} records in {1} ms.", count, tw.ElapsedMilliseconds); sess.Commit(); // Now go get the vm and lookup the items if (sess is SessionNoServer) { sess = new SessionNoServer(systemDir); } else { sess = new ServerClientSession(systemDir); } sess.BeginRead(); var vm2 = GetVersionManager(sess); if (vm2 != null) { Assert.IsTrue(vm2.Count > count - 1); person = vm2.Tip.GetTarget(false, sess); Assert.IsNotNull(person); var person2 = vm2.Tip.GetTarget(false, sess); Assert.AreSame(person, person2); Console.WriteLine("{0} records in version manager and tip is {1}.", vm2.Count, person2); } sess.Commit(); sess.BeginUpdate(); Database db = sess.OpenDatabase(VersionManager <VelocityDbSchema.Samples.Sample1.Person> .versionMangerDatabase, false, false); if (db != null) { sess.DeleteDatabase(db); } sess.Dispose(); }
public void b2ServerIterateDatabases() { using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginRead(); session.OpenAllDatabases(); session.Commit(); } }
public void dServerIterateDatabases() { 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(); } } }
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 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 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 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 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); } }
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 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 Recover1() { using (SessionNoServer session = new SessionNoServer(systemDir)) { Recover1(session); } using (ServerClientSession session = new ServerClientSession(systemDir)) { Recover1(session); } }
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 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 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 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 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(); } }
private void session1locking(object sender, RoutedEventArgs e) { if (session != null) try { if (session[0].InTransaction == false) if (session1server.IsChecked.Value) session[0] = new ServerClientSession(systemDir, null, int.Parse(session1LockTimeout.Text), session1optimistic.IsChecked.Value); else session[0] = new SessionNoServer(systemDir, int.Parse(session1LockTimeout.Text), session1optimistic.IsChecked.Value); else session1messages.Content = "Can only set OptimisticLocking attribute while not in a transaction"; } catch (Exception ex) { session1messages.Content = ex.Message; } }
/// <summary> /// Gets a cached session.If no session is available in the cache, a new one will be created. /// </summary> /// <returns></returns> ServerClientSession GetCachedSession() { ServerClientSession lSession = null; lock (sessions) { //if this is the fiirst call or we are out of sesssions create a new one if (sessions.Count == 0) { lSession= new ServerClientSession(GetDBDIrectory(), Environment.MachineName); } else { lSession = sessions[0]; sessions.RemoveAt(0); } } lSession.BeginUpdate(); return lSession; }
/// <summary> /// Gets a cached session.If no session is available in the cache, a new one will be created. /// </summary> /// <returns></returns> ServerClientSession GetCachedSession() { ServerClientSession lSession = null; lock (sessions) { //if this is the fiirst call or we are out of sesssions create a new one if (sessions.Count == 0) { lSession = new ServerClientSession(GetDBDIrectory(), Environment.MachineName); } else { lSession = sessions[0]; sessions.RemoveAt(0); } } lSession.BeginUpdate(); return(lSession); }
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); } }
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 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 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 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 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 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 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 Recover1() { using (SessionNoServer session = new SessionNoServer(systemDir)) { Recover1(session); } using (ServerClientSession session = new ServerClientSession(systemDir)) { Recover1(session); } }
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 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 = 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 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(); } }
//int WaitForMilliSeconds { get; set; } void BtnOkClick(object pSender, RoutedEventArgs pEvents) { m_federationInfo.UsesServerClient = (bool)RadioServer.IsChecked; m_federationInfo.ClassesFilenames = (from ListViewItem lItem in AssemblyList.Items select (string)lItem.Content).ToArray(); m_federationInfo.DependencyFiles = (from ListViewItem lItem in DependencyList.Items select (string)lItem.Content).ToArray(); m_federationInfo.SystemDbsPath = DBDirTextBox.Text; m_federationInfo.HostName = HostTextBox.Text; m_federationInfo.UsePessimisticLocking = (bool) PessimisticBox.IsChecked; m_federationInfo.WindowsAuthentication = (bool) WindowsAuthenticationBox.IsChecked; m_federationInfo.EnableSyncByTrackingChanges = (bool) EnableChangeTrackingBox.IsChecked; m_federationInfo.WaitForMilliSeconds = int.Parse(WaitForMilliSecondsTextBox.Text); bool createNew = (bool)CreateNewBox.IsChecked; string restoreFromPath = BackupDirTextBox.Text; string restoreFromHost = BackupHostTextBox.Text; if (createNew || (restoreFromPath != null && restoreFromPath.Length > 0)) { SessionBase session; if (m_federationInfo.UsesServerClient || (m_federationInfo.HostName.Length > 0 && m_federationInfo.HostName != Dns.GetHostName())) session = new ServerClientSession(m_federationInfo.SystemDbsPath, m_federationInfo.HostName); else session = new SessionNoServer(m_federationInfo.SystemDbsPath); if (m_federationInfo.EnableSyncByTrackingChanges) session.EnableSyncByTrackingChanges = true; session.BeginUpdate(); if (restoreFromPath != null && restoreFromPath.Length > 0) { UInt32 restoreFromRootDbNum = UInt32.Parse(BackupRootDbNumTextBox.Text); DateTime? restoreUpToDateTime = RestoreUpToDateTime.SelectedDate; session.RestoreFrom(restoreFromHost, restoreFromPath, restoreFromRootDbNum, restoreUpToDateTime == null ? DateTime.Now : restoreUpToDateTime.Value); } session.Commit(); } DialogResult = true; }
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 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); } }
void BtnOkClick(object pSender, RoutedEventArgs pEvents) { m_federationInfo.UsesServerClient = (bool)RadioServer.IsChecked; m_federationInfo.ClassesFilenames = (from ListViewItem lItem in AssemblyList.Items select (string)lItem.Content).ToArray(); m_federationInfo.DependencyFiles = (from ListViewItem lItem in DependencyList.Items select (string)lItem.Content).ToArray(); m_federationInfo.SystemDbsPath = DBDirTextBox.Text; m_federationInfo.HostName = HostTextBox.Text; m_federationInfo.UsePessimisticLocking = (bool) PessimisticBox.IsChecked; m_federationInfo.WindowsAuthentication = (bool) WindowsAuthenticationBox.IsChecked; bool createNew = (bool)CreateNewBox.IsChecked; if (createNew) { SessionBase session; if (m_federationInfo.UsesServerClient || (m_federationInfo.HostName.Length > 0 && m_federationInfo.HostName != Dns.GetHostName())) session = new ServerClientSession(m_federationInfo.SystemDbsPath, m_federationInfo.HostName); else session = new SessionNoServer(m_federationInfo.SystemDbsPath); session.BeginUpdate(); session.Commit(); } DialogResult = true; }