Merge pull request #7152 from ipfs/fix/sharness-partial-publish

fix: invalidate cache on failed publish
This commit is contained in:
Steven Allen 2020-04-13 18:43:26 -07:00 committed by GitHub
commit b760d89e02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 6 deletions

View File

@ -49,6 +49,13 @@ func (ns *mpns) cacheSet(name string, val path.Path, ttl time.Duration) {
})
}
func (ns *mpns) cacheInvalidate(name string) {
if ns.cache == nil {
return
}
ns.cache.Remove(name)
}
type cacheEntry struct {
val path.Path
eol time.Time

View File

@ -218,6 +218,9 @@ func (ns *mpns) PublishWithEOL(ctx context.Context, name ci.PrivKey, value path.
return err
}
if err := ns.ipnsPublisher.PublishWithEOL(ctx, name, value, eol); err != nil {
// Invalidate the cache. Publishing may _partially_ succeed but
// still return an error.
ns.cacheInvalidate(peer.Encode(id))
return err
}
ttl := DefaultResolverCacheTTL

View File

@ -153,17 +153,24 @@ test_resolve_cmd_fail() {
test_resolve "/ipld/$dag_hash/i/j" "/ipld/$dag_hash/i/j"
test_resolve "/ipld/$dag_hash/i" "/ipld/$dag_hash/i"
# At the moment, publishing _fails_ because we fail to put to the DHT.
# However, resolving succeeds because we resolve the record we put to our own
# node.
#
# We should find a nice way to truly support offline publishing. But this
# behavior isn't terrible.
test_resolve_setup_name_fail "self" "/ipfs/$a_hash"
test_resolve_fail "/ipns/$self_hash" "/ipfs/$a_hash"
test_resolve_fail "/ipns/$self_hash/b" "/ipfs/$b_hash"
test_resolve_fail "/ipns/$self_hash/b/c" "/ipfs/$c_hash"
test_resolve "/ipns/$self_hash" "/ipfs/$a_hash"
test_resolve "/ipns/$self_hash/b" "/ipfs/$b_hash"
test_resolve "/ipns/$self_hash/b/c" "/ipfs/$c_hash"
test_resolve_setup_name_fail "self" "/ipfs/$b_hash"
test_resolve_fail "/ipns/$self_hash" "/ipfs/$b_hash"
test_resolve_fail "/ipns/$self_hash/c" "/ipfs/$c_hash"
test_resolve "/ipns/$self_hash" "/ipfs/$b_hash"
test_resolve "/ipns/$self_hash/c" "/ipfs/$c_hash"
test_resolve_setup_name_fail "self" "/ipfs/$c_hash"
test_resolve_fail "/ipns/$self_hash" "/ipfs/$c_hash"
test_resolve "/ipns/$self_hash" "/ipfs/$c_hash"
}
# should work offline