Skip to content

Commit

Permalink
Merge pull request #7152 from ipfs/fix/sharness-partial-publish
Browse files Browse the repository at this point in the history
fix: invalidate cache on failed publish
  • Loading branch information
Stebalien authored Apr 14, 2020
2 parents af2f4b2 + c12c184 commit b760d89
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
7 changes: 7 additions & 0 deletions namesys/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions namesys/namesys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 13 additions & 6 deletions test/sharness/t0160-resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b760d89

Please sign in to comment.