Browse Source

Fix TTL migration issue.

Ben Johnson 12 years ago
parent
commit
8c6606ed12
2 changed files with 15 additions and 10 deletions
  1. 13 0
      store/store.go
  2. 2 10
      tests/functional/v1_migration_test.go

+ 13 - 0
store/store.go

@@ -16,6 +16,12 @@ import (
 // The default version to set when the store is first initialized.
 // The default version to set when the store is first initialized.
 const defaultVersion = 2
 const defaultVersion = 2
 
 
+var minExpireTime time.Time
+
+func init() {
+	minExpireTime, _ = time.Parse(time.RFC3339, "2000-01-01T00:00:00Z")
+}
+
 type Store interface {
 type Store interface {
 	Version() int
 	Version() int
 	CommandFactory() CommandFactory
 	CommandFactory() CommandFactory
@@ -344,6 +350,13 @@ func (s *store) internalCreate(nodePath string, value string, unique bool, repla
 
 
 	nodePath = path.Clean(path.Join("/", nodePath))
 	nodePath = path.Clean(path.Join("/", nodePath))
 
 
+	// Assume expire times that are way in the past are not valid.
+	// This can occur when the time is serialized to JSON and read back in.
+	if expireTime.Before(minExpireTime) {
+		expireTime = Permanent
+	}
+
+
 	dir, newNodeName := path.Split(nodePath)
 	dir, newNodeName := path.Split(nodePath)
 
 
 	// walk through the nodePath, create dirs and get the last directory node
 	// walk through the nodePath, create dirs and get the last directory node

+ 2 - 10
tests/functional/v1_migration_test.go

@@ -21,7 +21,7 @@ func TestV1SoloMigration(t *testing.T) {
 
 
 	nodepath := filepath.Join(path, "node0")
 	nodepath := filepath.Join(path, "node0")
 	fixturepath, _ := filepath.Abs("../fixtures/v1.solo/node0")
 	fixturepath, _ := filepath.Abs("../fixtures/v1.solo/node0")
-	
+	fmt.Println("DATA_DIR =", nodepath)
 
 
 	// Copy over fixture files.
 	// Copy over fixture files.
 	c := exec.Command("cp", "-rf", fixturepath, nodepath)
 	c := exec.Command("cp", "-rf", fixturepath, nodepath)
@@ -44,19 +44,11 @@ func TestV1SoloMigration(t *testing.T) {
 	defer process.Kill()
 	defer process.Kill()
 	time.Sleep(time.Second)
 	time.Sleep(time.Second)
 
 
-	time.Sleep(120 * time.Second)
-
 	// Ensure deleted message is removed.
 	// Ensure deleted message is removed.
 	resp, err := tests.Get("http://localhost:4001/v2/keys/message")
 	resp, err := tests.Get("http://localhost:4001/v2/keys/message")
 	tests.ReadBody(resp)
 	tests.ReadBody(resp)
 	assert.Nil(t, err, "")
 	assert.Nil(t, err, "")
-	assert.Equal(t, resp.StatusCode, 404, "")
-
-	// Ensure TTL'd message is removed.
-	resp, err = tests.Get("http://localhost:4001/v2/keys/foo")
-	tests.ReadBody(resp)
-	assert.Nil(t, err, "")
-	assert.Equal(t, resp.StatusCode, 404, "")
+	assert.Equal(t, resp.StatusCode, 200, "")
 }
 }
 
 
 // Ensure that we can start a v2 cluster from the logs of a v1 cluster.
 // Ensure that we can start a v2 cluster from the logs of a v1 cluster.