From 07139e453ad5576171b2e1fbcee36f6d38773fc8 Mon Sep 17 00:00:00 2001 From: Mathias Lafeldt Date: Tue, 18 Feb 2020 18:47:15 +0100 Subject: [PATCH] backend/remote-state/oss: extract pkName constant --- backend/remote-state/oss/backend_test.go | 2 +- backend/remote-state/oss/client.go | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/backend/remote-state/oss/backend_test.go b/backend/remote-state/oss/backend_test.go index e292bdd7d4..c81367bb4c 100644 --- a/backend/remote-state/oss/backend_test.go +++ b/backend/remote-state/oss/backend_test.go @@ -181,7 +181,7 @@ func deleteOSSBucket(t *testing.T, ossClient *oss.Client, bucketName string) { func createTablestoreTable(t *testing.T, otsClient *tablestore.TableStoreClient, tableName string) { tableMeta := new(tablestore.TableMeta) tableMeta.TableName = tableName - tableMeta.AddPrimaryKeyColumn("LockID", tablestore.PrimaryKeyType_STRING) + tableMeta.AddPrimaryKeyColumn(pkName, tablestore.PrimaryKeyType_STRING) tableOption := new(tablestore.TableOption) tableOption.TimeToAlive = -1 diff --git a/backend/remote-state/oss/client.go b/backend/remote-state/oss/client.go index 0b3c5ad514..cd28458cbe 100644 --- a/backend/remote-state/oss/client.go +++ b/backend/remote-state/oss/client.go @@ -21,9 +21,11 @@ import ( "github.com/pkg/errors" ) -// Store the last saved serial in tablestore with this suffix for consistency checks. const ( + // Store the last saved serial in tablestore with this suffix for consistency checks. stateIDSuffix = "-md5" + + pkName = "LockID" ) var ( @@ -165,7 +167,7 @@ func (c *RemoteClient) Lock(info *state.LockInfo) (string, error) { PrimaryKey: &tablestore.PrimaryKey{ PrimaryKeys: []*tablestore.PrimaryKeyColumn{ { - ColumnName: "LockID", + ColumnName: pkName, Value: c.lockPath(), }, }, @@ -214,12 +216,12 @@ func (c *RemoteClient) getMD5() ([]byte, error) { PrimaryKey: &tablestore.PrimaryKey{ PrimaryKeys: []*tablestore.PrimaryKeyColumn{ { - ColumnName: "LockID", + ColumnName: pkName, Value: c.lockPath() + stateIDSuffix, }, }, }, - ColumnsToGet: []string{"LockID", "Digest"}, + ColumnsToGet: []string{pkName, "Digest"}, MaxVersion: 1, } @@ -261,7 +263,7 @@ func (c *RemoteClient) putMD5(sum []byte) error { PrimaryKey: &tablestore.PrimaryKey{ PrimaryKeys: []*tablestore.PrimaryKeyColumn{ { - ColumnName: "LockID", + ColumnName: pkName, Value: c.lockPath() + stateIDSuffix, }, }, @@ -302,7 +304,7 @@ func (c *RemoteClient) deleteMD5() error { PrimaryKey: &tablestore.PrimaryKey{ PrimaryKeys: []*tablestore.PrimaryKeyColumn{ { - ColumnName: "LockID", + ColumnName: pkName, Value: c.lockPath() + stateIDSuffix, }, }, @@ -328,12 +330,12 @@ func (c *RemoteClient) getLockInfo() (*state.LockInfo, error) { PrimaryKey: &tablestore.PrimaryKey{ PrimaryKeys: []*tablestore.PrimaryKeyColumn{ { - ColumnName: "LockID", + ColumnName: pkName, Value: c.lockPath(), }, }, }, - ColumnsToGet: []string{"LockID", "Info"}, + ColumnsToGet: []string{pkName, "Info"}, MaxVersion: 1, } @@ -381,7 +383,7 @@ func (c *RemoteClient) Unlock(id string) error { PrimaryKey: &tablestore.PrimaryKey{ PrimaryKeys: []*tablestore.PrimaryKeyColumn{ { - ColumnName: "LockID", + ColumnName: pkName, Value: c.lockPath(), }, },