Skip to content

Commit

Permalink
Fix(increment): Fix readTs less than minTs (#6317)
Browse files Browse the repository at this point in the history
Use the readTs for reads via LocalCache. This would ensure that users don't get a lot of ReadTs less than MinTs errors. This PR also fixes the flaky test in increment_test.go.

This has a side-effect on posting list cache. That cache would need to understand versioning to be effective.

Co-authored-by: Daniel Mai <daniel@dgraph.io>
(cherry picked from commit 2de4675)
  • Loading branch information
manishrjain authored and parasssh committed Sep 18, 2020
1 parent f7145fc commit 1aaa206
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
File renamed without changes.
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

// Package counter builds a tool that retrieves a value for UID=0x01, and increments
// Package increment builds a tool that retrieves a value for UID=0x01, and increments
// it by 1. If successful, it prints out the incremented value. It assumes that it has
// access to UID=0x01, and that `val` predicate is of type int.
package counter
package increment

import (
"context"
Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package counter
package increment

import (
"context"
Expand Down
4 changes: 2 additions & 2 deletions dgraph/cmd/root.go
Expand Up @@ -25,9 +25,9 @@ import (
"github.com/dgraph-io/dgraph/dgraph/cmd/bulk"
"github.com/dgraph-io/dgraph/dgraph/cmd/cert"
"github.com/dgraph-io/dgraph/dgraph/cmd/conv"
"github.com/dgraph-io/dgraph/dgraph/cmd/counter"
"github.com/dgraph-io/dgraph/dgraph/cmd/debug"
"github.com/dgraph-io/dgraph/dgraph/cmd/debuginfo"
"github.com/dgraph-io/dgraph/dgraph/cmd/increment"
"github.com/dgraph-io/dgraph/dgraph/cmd/live"
"github.com/dgraph-io/dgraph/dgraph/cmd/migrate"
"github.com/dgraph-io/dgraph/dgraph/cmd/version"
Expand Down Expand Up @@ -75,7 +75,7 @@ var rootConf = viper.New()
// subcommands initially contains all default sub-commands.
var subcommands = []*x.SubCommand{
&bulk.Bulk, &cert.Cert, &conv.Conv, &live.Live, &alpha.Alpha, &zero.Zero, &version.Version,
&debug.Debug, &counter.Increment, &migrate.Migrate, &debuginfo.DebugInfo, &upgrade.Upgrade,
&debug.Debug, &increment.Increment, &migrate.Migrate, &debuginfo.DebugInfo, &upgrade.Upgrade,
}

func initCmds() {
Expand Down
11 changes: 8 additions & 3 deletions posting/lists.go
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"io/ioutil"
"math"
"os"
"os/exec"
"runtime"
Expand Down Expand Up @@ -181,6 +180,12 @@ func NewLocalCache(startTs uint64) *LocalCache {
}
}

// NoCache returns a new LocalCache instance, which won't cache anything. Useful to pass startTs
// around.
func NoCache(startTs uint64) *LocalCache {
return &LocalCache{startTs: startTs}
}

func (lc *LocalCache) getNoStore(key string) *List {
lc.RLock()
defer lc.RUnlock()
Expand All @@ -205,8 +210,8 @@ func (lc *LocalCache) SetIfAbsent(key string, updated *List) *List {
}

func (lc *LocalCache) getInternal(key []byte, readFromDisk bool) (*List, error) {
if lc == nil {
return getNew(key, pstore, math.MaxUint64)
if lc.plists == nil {
return getNew(key, pstore, lc.startTs)
}
skey := string(key)
if pl := lc.getNoStore(skey); pl != nil {
Expand Down
3 changes: 3 additions & 0 deletions worker/task.go
Expand Up @@ -881,6 +881,9 @@ func processTask(ctx context.Context, q *pb.Query, gid uint32) (*pb.Result, erro
if q.Cache == UseTxnCache {
qs.cache = posting.Oracle().CacheAt(q.ReadTs)
}
if qs.cache == nil {
qs.cache = posting.NoCache(q.ReadTs)
}
// For now, remove the query level cache. It is causing contention for queries with high
// fan-out.

Expand Down

0 comments on commit 1aaa206

Please sign in to comment.