(namespace, tableName, columnName string, enumCases []string)
| 55 | } |
| 56 | |
| 57 | func (e *enumMutator) ExtendEnumCases(namespace, tableName, columnName string, enumCases []string) ([]int, error) { |
| 58 | schema, err := e.schemaMutator.GetTable(namespace, tableName) |
| 59 | if err != nil { |
| 60 | return nil, err |
| 61 | } |
| 62 | columnID := -1 |
| 63 | for id, column := range schema.Columns { |
| 64 | if column.Name == columnName && !column.Deleted && column.IsEnumColumn() { |
| 65 | columnID = id |
| 66 | break |
| 67 | } |
| 68 | } |
| 69 | if columnID < 0 { |
| 70 | return nil, metaCom.ErrColumnDoesNotExist |
| 71 | } |
| 72 | |
| 73 | e.RLock() |
| 74 | enumCache, exist := e.enumCacheMap[getCacheKey(namespace, tableName, schema.Incarnation, columnID)] |
| 75 | if !exist { |
| 76 | e.RUnlock() |
| 77 | // fetch enum case from etcd and update cache |
| 78 | return e.extendEnumCase(namespace, tableName, schema.Incarnation, columnID, 0, enumCases) |
| 79 | } |
| 80 | |
| 81 | currentNodeID := enumCache.currentNodeID |
| 82 | // check enum cache for existing enums |
| 83 | enumIDs := make([]int, len(enumCases)) |
| 84 | newEnumCases := make([]string, 0) |
| 85 | for index, enum := range enumCases { |
| 86 | enumID, exist := enumCache.enumCases[enum] |
| 87 | if !exist { |
| 88 | enumIDs[index] = -1 |
| 89 | newEnumCases = append(newEnumCases, enum) |
| 90 | } else { |
| 91 | enumIDs[index] = enumID |
| 92 | } |
| 93 | } |
| 94 | e.RUnlock() |
| 95 | |
| 96 | if len(newEnumCases) > 0 { |
| 97 | // fetch enum cases from etcd and update cache |
| 98 | missingIDs, err := e.extendEnumCase(namespace, tableName, schema.Incarnation, columnID, currentNodeID, newEnumCases) |
| 99 | if err != nil { |
| 100 | return nil, err |
| 101 | } |
| 102 | // missingID is ordered the same as newEnumCases |
| 103 | // which is the same order in enumIDs |
| 104 | i := 0 |
| 105 | for index, enumID := range enumIDs { |
| 106 | if enumID < 0 { |
| 107 | enumIDs[index] = missingIDs[i] |
| 108 | i++ |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | return enumIDs, nil |
| 113 | } |
| 114 |
nothing calls this directly
no test coverage detected