You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Etag calculation is done by marshaling the payload into json and getting the md5 of that string. All values will be converted to string, and there are some specific cases in which the conversion to string depends on external state, like its time.Time. Its sting will depend on the local timezone.
This is not an issue if the item is only processed by a single computer (or a set of them on the same timezone), but I found a case in which this is not the case. I am using postgres replica through kafka events to replicate part of the state from one service to another, and both needs to be on different timezone, causing the same item in two different systems to have a different Etags. This is an issue in the moment I am considering the Etag and the Id as the replica identity.
I think we should guaranty that for same time.Time's, the Etag will be always the same independently of external states, and I suggest to do something like this on the getEtag function:
func normalizeTime(payload map[string]interface{}) map[string]interface{} {
for k,v := range payload {
switch v.(type){
case time.Time:
if t, ok := v.(time.Time) ; ok {
payload[k] = t.UnixNano()
}
case map[string]interface{}:
if t, ok := v.(map[string]interface{}) ; ok {
normalizeTime(t)
}
case []interface{}:
if t, ok := v.([]interface{}) ; ok {
for i,_ := range t {
if x, ok := t[i].(time.Time) ; ok {
t[i] = x.UnixNano()
}
}
}
}
}
return payload
}
If you agree with that I can work on making the a proper PR.
The text was updated successfully, but these errors were encountered:
This is happening to me, particularly, on the "created" and "updated" fields, because they are initialised using the function Now, which uses time.Now() that considers location on the internal state.
So, other possible solutions is to prevent them to manage the location state by just adding a call to UTC() on the Now function;
Now = func(ctx context.Context, value interface{}) interface{} {
return time.Now()**.UTC()**
}
Etag calculation is done by marshaling the payload into json and getting the md5 of that string. All values will be converted to string, and there are some specific cases in which the conversion to string depends on external state, like its time.Time. Its sting will depend on the local timezone.
This is not an issue if the item is only processed by a single computer (or a set of them on the same timezone), but I found a case in which this is not the case. I am using postgres replica through kafka events to replicate part of the state from one service to another, and both needs to be on different timezone, causing the same item in two different systems to have a different Etags. This is an issue in the moment I am considering the Etag and the Id as the replica identity.
This is the database on service A:
And this is on service B:
I think we should guaranty that for same time.Time's, the Etag will be always the same independently of external states, and I suggest to do something like this on the getEtag function:
If you agree with that I can work on making the a proper PR.
The text was updated successfully, but these errors were encountered: