MCPcopy
hub / github.com/dgraph-io/dgraph / checkDgraphVersion

Method checkDgraphVersion

dgraphtest/local_cluster.go:1244–1271  ·  view source on GitHub ↗
(containerID string)

Source from the content-addressed store, hash-verified

1242}
1243
1244func (c *LocalCluster) checkDgraphVersion(containerID string) error {
1245 if c.GetVersion() == localVersion {
1246 return nil
1247 }
1248
1249 contLogs, err := c.getLogs(containerID)
1250 if err != nil {
1251 return errors.Wrapf(err, "error during checkDgraphVersion for container [%v]", containerID)
1252 }
1253
1254 // During in-place upgrade, container remains same but logs have version string twice
1255 // once for old version, once for new. Want new version string. Look bottom-up using
1256 // LastIndex to get latest version's string.
1257 index := strings.LastIndex(contLogs, "Commit SHA-1 : ")
1258 running := strings.Fields(contLogs[index : index+70])[3] // 70 is arbitrary
1259 chash, err := getHash(c.GetVersion())
1260 if err != nil {
1261 return errors.Wrapf(err, "error while getting hash for %v", c.GetVersion())
1262 }
1263 rhash, err := getHash(running)
1264 if err != nil {
1265 return errors.Wrapf(err, "error while getting hash for %v", running)
1266 }
1267 if chash != rhash {
1268 return errors.Errorf("found different dgraph version [%v] than expected [%v]", rhash, chash)
1269 }
1270 return nil
1271}
1272
1273func (c *LocalCluster) getLogs(containerID string) (string, error) {
1274 ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)

Callers 1

HealthCheckMethod · 0.95

Calls 6

GetVersionMethod · 0.95
getLogsMethod · 0.95
getHashFunction · 0.70
FieldsMethod · 0.65
LastIndexMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected