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();
   }
 }
Exemplo n.º 2
0
        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();
            }
        }
Exemplo n.º 3
0
 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();
   }
 }
Exemplo n.º 4
0
 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();
     }
 }
Exemplo n.º 5
0
        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();
                    }
                }
            });
        }
Exemplo n.º 6
0
        [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);
            }
        }
Exemplo n.º 7
0
    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();
          }
        }
      });
    }
Exemplo n.º 8
0
    [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);
      }
    }