backend/remote-state/oss: extract pkName constant

This commit is contained in:
Mathias Lafeldt 2020-02-18 18:47:15 +01:00
parent a4178d12d6
commit 07139e453a
No known key found for this signature in database
GPG Key ID: 15F939C6FE84FECF
2 changed files with 12 additions and 10 deletions

View File

@ -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

View File

@ -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(),
},
},