@@ -44,85 +44,73 @@ const (
44
44
TableDroppedGCState TableGCState = ""
45
45
)
46
46
47
+ func (s TableGCState ) TableHint () InternalTableHint {
48
+ if hint , ok := gcStatesTableHints [s ]; ok {
49
+ return hint
50
+ }
51
+ return InternalTableUnknownHint
52
+ }
53
+
47
54
const (
48
- GCTableNameExpression string = `^_vt_(HOLD|PURGE|EVAC|DROP)_([0-f]{32})_([0-9]{14})$`
49
- // NewGCTableNameExpression parses new intrnal table name format, e.g. _vt_hld_6ace8bcef73211ea87e9f875a4d24e90_20200915120410_
50
- NewGCTableNameExpression string = `^_vt_(hld|prg|evc|drp)_([0-f]{32})_([0-9]{14})_$`
55
+ OldGCTableNameExpression string = `^_vt_(HOLD|PURGE|EVAC|DROP)_([0-f]{32})_([0-9]{14})$`
56
+ // GCTableNameExpression parses new internal table name format, e.g. _vt_hld_6ace8bcef73211ea87e9f875a4d24e90_20200915120410_
57
+ GCTableNameExpression string = `^_vt_(hld|prg|evc|drp)_([0-f]{32})_([0-9]{14})_$`
51
58
)
52
59
53
60
var (
54
- gcUUIDRegexp = regexp .MustCompile (`^[0-f]{32}$` )
55
- gcTableNameRegexp = regexp .MustCompile (GCTableNameExpression )
56
-
57
- gcStates = map [string ]TableGCState {
58
- string (HoldTableGCState ): HoldTableGCState ,
59
- "hld" : HoldTableGCState ,
60
- string (PurgeTableGCState ): PurgeTableGCState ,
61
- "prg" : PurgeTableGCState ,
62
- string (EvacTableGCState ): EvacTableGCState ,
63
- "evc" : EvacTableGCState ,
64
- string (DropTableGCState ): DropTableGCState ,
65
- "drp" : DropTableGCState ,
66
- }
61
+ condensedUUIDRegexp = regexp .MustCompile (`^[0-f]{32}$` )
62
+ oldGCTableNameRegexp = regexp .MustCompile (OldGCTableNameExpression )
63
+
64
+ gcStates = map [string ]TableGCState {}
65
+ gcStatesTableHints = map [TableGCState ]InternalTableHint {}
67
66
)
68
67
69
- // IsGCUUID answers 'true' when the given string is an GC UUID, e.g.:
70
- // a0638f6bec7b11ea9bf8000d3a9b8a9a
71
- func IsGCUUID (uuid string ) bool {
72
- return gcUUIDRegexp .MatchString (uuid )
68
+ func init () {
69
+ gcStatesTableHints [HoldTableGCState ] = InternalTableGCHoldHint
70
+ gcStatesTableHints [PurgeTableGCState ] = InternalTableGCPurgeHint
71
+ gcStatesTableHints [EvacTableGCState ] = InternalTableGCEvacHint
72
+ gcStatesTableHints [DropTableGCState ] = InternalTableGCDropHint
73
+ for _ , gcState := range []TableGCState {HoldTableGCState , PurgeTableGCState , EvacTableGCState , DropTableGCState } {
74
+ gcStates [string (gcState )] = gcState
75
+ gcStates [gcState .TableHint ().String ()] = gcState
76
+ }
73
77
}
74
78
75
79
// generateGCTableName creates a GC table name, based on desired state and time, and with optional preset UUID.
76
80
// If uuid is given, then it must be in GC-UUID format. If empty, the function auto-generates a UUID.
77
- func generateGCTableName (state TableGCState , uuid string , t time.Time ) (tableName string , err error ) {
81
+ func generateGCTableNameOldFormat (state TableGCState , uuid string , t time.Time ) (tableName string , err error ) {
78
82
if uuid == "" {
79
83
uuid , err = CreateUUIDWithDelimiter ("" )
80
84
}
81
85
if err != nil {
82
86
return "" , err
83
87
}
84
- if ! IsGCUUID (uuid ) {
88
+ if ! isCondensedUUID (uuid ) {
85
89
return "" , fmt .Errorf ("Not a valid GC UUID format: %s" , uuid )
86
90
}
87
91
timestamp := ToReadableTimestamp (t )
88
92
return fmt .Sprintf ("_vt_%s_%s_%s" , state , uuid , timestamp ), nil
89
93
}
90
94
91
- // generateGCTableNameNewFormat creates a GC table name, based on desired state and time, and with optional preset UUID.
95
+ // generateGCTableName creates a GC table name, based on desired state and time, and with optional preset UUID.
92
96
// If uuid is given, then it must be in GC-UUID format. If empty, the function auto-generates a UUID.
93
- func generateGCTableNameNewFormat (state TableGCState , uuid string , t time.Time ) (tableName string , err error ) {
94
- if uuid == "" {
95
- uuid , err = CreateUUIDWithDelimiter ("" )
96
- }
97
- if err != nil {
98
- return "" , err
99
- }
100
- if ! IsGCUUID (uuid ) {
101
- return "" , fmt .Errorf ("Not a valid GC UUID format: %s" , uuid )
102
- }
103
- timestamp := ToReadableTimestamp (t )
104
- var hint string
97
+ func generateGCTableName (state TableGCState , uuid string , t time.Time ) (tableName string , err error ) {
105
98
for k , v := range gcStates {
106
99
if v != state {
107
100
continue
108
101
}
109
102
if len (k ) == 3 && k != string (state ) { // the "new" format
110
- hint = k
103
+ return GenerateInternalTableName ( k , uuid , t )
111
104
}
112
105
}
113
- return fmt .Sprintf ( "_vt_%s_%s_%s_" , hint , uuid , timestamp ), nil
106
+ return "" , fmt .Errorf ( "Unknown GC state: %v" , state )
114
107
}
115
108
116
109
// GenerateGCTableName creates a GC table name, based on desired state and time, and with random UUID
117
110
func GenerateGCTableName (state TableGCState , t time.Time ) (tableName string , err error ) {
118
111
return generateGCTableName (state , "" , t )
119
112
}
120
113
121
- // GenerateGCTableNameNewFormat creates a GC table name, based on desired state and time, and with random UUID
122
- func GenerateGCTableNameNewFormat (state TableGCState , t time.Time ) (tableName string , err error ) {
123
- return generateGCTableNameNewFormat (state , "" , t )
124
- }
125
-
126
114
// AnalyzeGCTableName analyzes a given table name to see if it's a GC table, and if so, parse out
127
115
// its state, uuid, and timestamp
128
116
func AnalyzeGCTableName (tableName string ) (isGCTable bool , state TableGCState , uuid string , t time.Time , err error ) {
@@ -134,7 +122,7 @@ func AnalyzeGCTableName(tableName string) (isGCTable bool, state TableGCState, u
134
122
}
135
123
// Try old naming formats. These names will not be generated in v20.
136
124
// TODO(shlomi): the code below should be remvoed in v21
137
- submatch := gcTableNameRegexp .FindStringSubmatch (tableName )
125
+ submatch := oldGCTableNameRegexp .FindStringSubmatch (tableName )
138
126
if len (submatch ) == 0 {
139
127
return false , state , uuid , t , nil
140
128
}
@@ -165,8 +153,8 @@ func GenerateRenameStatementWithUUID(fromTableName string, state TableGCState, u
165
153
}
166
154
167
155
// GenerateRenameStatementWithUUIDNewFormat generates a "RENAME TABLE" statement, where a table is renamed to a GC table, with preset UUID
168
- func GenerateRenameStatementWithUUIDNewFormat (fromTableName string , state TableGCState , uuid string , t time.Time ) (statement string , toTableName string , err error ) {
169
- toTableName , err = generateGCTableNameNewFormat (state , uuid , t )
156
+ func generateRenameStatementWithUUIDOldFormat (fromTableName string , state TableGCState , uuid string , t time.Time ) (statement string , toTableName string , err error ) {
157
+ toTableName , err = generateGCTableNameOldFormat (state , uuid , t )
170
158
if err != nil {
171
159
return "" , "" , err
172
160
}
@@ -179,8 +167,8 @@ func GenerateRenameStatement(fromTableName string, state TableGCState, t time.Ti
179
167
}
180
168
181
169
// GenerateRenameStatement generates a "RENAME TABLE" statement, where a table is renamed to a GC table.
182
- func GenerateRenameStatementNewFormat (fromTableName string , state TableGCState , t time.Time ) (statement string , toTableName string , err error ) {
183
- return GenerateRenameStatementWithUUIDNewFormat (fromTableName , state , "" , t )
170
+ func GenerateRenameStatementOldFormat (fromTableName string , state TableGCState , t time.Time ) (statement string , toTableName string , err error ) {
171
+ return generateRenameStatementWithUUIDOldFormat (fromTableName , state , "" , t )
184
172
}
185
173
186
174
// ParseGCLifecycle parses a comma separated list of gc states and returns a map of indicated states
0 commit comments