Browse Source

etcdserver: rename db file into a formal directory

and rename it to a formal name
Yicheng Qin 10 years ago
parent
commit
05c74bd890
2 changed files with 10 additions and 3 deletions
  1. 2 0
      etcdserver/config.go
  2. 8 3
      etcdserver/server.go

+ 2 - 0
etcdserver/config.go

@@ -119,6 +119,8 @@ func (c *ServerConfig) WALDir() string {
 
 
 func (c *ServerConfig) SnapDir() string { return path.Join(c.MemberDir(), "snap") }
 func (c *ServerConfig) SnapDir() string { return path.Join(c.MemberDir(), "snap") }
 
 
+func (c *ServerConfig) StorageDir() string { return path.Join(c.MemberDir(), "storage") }
+
 func (c *ServerConfig) ShouldDiscover() bool { return c.DiscoveryURL != "" }
 func (c *ServerConfig) ShouldDiscover() bool { return c.DiscoveryURL != "" }
 
 
 // ReqTimeout returns timeout for request to finish.
 // ReqTimeout returns timeout for request to finish.

+ 8 - 3
etcdserver/server.go

@@ -62,6 +62,8 @@ const (
 
 
 	purgeFileInterval      = 30 * time.Second
 	purgeFileInterval      = 30 * time.Second
 	monitorVersionInterval = 5 * time.Second
 	monitorVersionInterval = 5 * time.Second
+
+	databaseFilename = "db"
 )
 )
 
 
 var (
 var (
@@ -181,8 +183,7 @@ func NewServer(cfg *ServerConfig) (*EtcdServer, error) {
 	var id types.ID
 	var id types.ID
 	var cl *cluster
 	var cl *cluster
 
 
-	demoFile := path.Join(cfg.MemberDir(), "v3demo")
-	if !cfg.V3demo && fileutil.Exist(demoFile) {
+	if !cfg.V3demo && fileutil.Exist(path.Join(cfg.StorageDir(), databaseFilename)) {
 		return nil, errors.New("experimental-v3demo cannot be disabled once it is enabled")
 		return nil, errors.New("experimental-v3demo cannot be disabled once it is enabled")
 	}
 	}
 
 
@@ -330,7 +331,11 @@ func NewServer(cfg *ServerConfig) (*EtcdServer, error) {
 	}
 	}
 
 
 	if cfg.V3demo {
 	if cfg.V3demo {
-		srv.kv = dstorage.New(demoFile)
+		err = os.MkdirAll(cfg.StorageDir(), privateDirMode)
+		if err != nil && err != os.ErrExist {
+			return nil, err
+		}
+		srv.kv = dstorage.New(path.Join(cfg.StorageDir(), databaseFilename))
 	}
 	}
 
 
 	// TODO: move transport initialization near the definition of remote
 	// TODO: move transport initialization near the definition of remote