public override void Open(IFile file, long pagePoolSize)
        {
            if (opened)
            {
                throw new StorageError(StorageError.ErrorCode.STORAGE_ALREADY_OPENED);
            }
            initialize(file, pagePoolSize);

            lck       = new PersistentResource();
            init      = new object();
            sync      = new object();
            done      = new object();
            commit    = new object();
            listening = true;
            Connect();
            if (socket != null)
            {
                thread = new Thread(new ThreadStart(run));
                thread.Start();
                WaitSynchronizationCompletion();
                WaitInitializationCompletion();
            }
            opened = true;
            BeginThreadTransaction(TransactionMode.ReplicationSlave);
            reloadScheme();
            EndThreadTransaction();
        }
Ejemplo n.º 2
0
 public override void Open(IFile file, int cacheSizeInBytes)
 {
     acceptor = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     acceptor.Bind(new IPEndPoint(IPAddress.Any, port));
     acceptor.Listen(ListenQueueSize);
     if (file.Length > 0)
     {
         byte[] rootPage = new byte[Page.pageSize];
         try
         {
             file.Read(0, rootPage);
             prevIndex   = rootPage[DB_HDR_CURR_INDEX_OFFSET];
             initialized = rootPage[DB_HDR_INITIALIZED_OFFSET] != 0;
         }
         catch (DatabaseException)
         {
             initialized = false;
             prevIndex   = -1;
         }
     }
     else
     {
         prevIndex   = -1;
         initialized = false;
     }
     this.file = file;
     lck       = new PersistentResource();
     init      = new object();
     done      = new object();
     commit    = new object();
     listening = true;
     connect();
     pool = new PagePool(cacheSizeInBytes / Page.pageSize);
     pool.open(file);
     thread      = new Thread(new ThreadStart(run));
     thread.Name = "ReplicationSlaveStorageImpl";
     thread.Start();
     WaitInitializationCompletion();
     base.Open(file, cacheSizeInBytes);
 }