Skip to content

Commit 56c50ed

Browse files
parassshmanishrjain
parasssh
andauthored
Fix(increment): Fix readTs less than minTs (#6317) (#6518)
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 <[email protected]> (cherry picked from commit 2de4675) Co-authored-by: Manish R Jain <[email protected]>
1 parent d977446 commit 56c50ed

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed
File renamed without changes.

dgraph/cmd/counter/increment.go renamed to dgraph/cmd/increment/increment.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

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

2222
import (
2323
"context"

dgraph/cmd/counter/increment_test.go renamed to dgraph/cmd/increment/increment_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package counter
17+
package increment
1818

1919
import (
2020
"context"

dgraph/cmd/root.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525
"github.com/dgraph-io/dgraph/dgraph/cmd/bulk"
2626
"github.com/dgraph-io/dgraph/dgraph/cmd/cert"
2727
"github.com/dgraph-io/dgraph/dgraph/cmd/conv"
28-
"github.com/dgraph-io/dgraph/dgraph/cmd/counter"
2928
"github.com/dgraph-io/dgraph/dgraph/cmd/debug"
3029
"github.com/dgraph-io/dgraph/dgraph/cmd/debuginfo"
30+
"github.com/dgraph-io/dgraph/dgraph/cmd/increment"
3131
"github.com/dgraph-io/dgraph/dgraph/cmd/live"
3232
"github.com/dgraph-io/dgraph/dgraph/cmd/migrate"
3333
"github.com/dgraph-io/dgraph/dgraph/cmd/version"
@@ -75,7 +75,7 @@ var rootConf = viper.New()
7575
// subcommands initially contains all default sub-commands.
7676
var subcommands = []*x.SubCommand{
7777
&bulk.Bulk, &cert.Cert, &conv.Conv, &live.Live, &alpha.Alpha, &zero.Zero, &version.Version,
78-
&debug.Debug, &counter.Increment, &migrate.Migrate, &debuginfo.DebugInfo, &upgrade.Upgrade,
78+
&debug.Debug, &increment.Increment, &migrate.Migrate, &debuginfo.DebugInfo, &upgrade.Upgrade,
7979
}
8080

8181
func initCmds() {

posting/lists.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"fmt"
2222
"io/ioutil"
23-
"math"
2423
"os"
2524
"os/exec"
2625
"runtime"
@@ -181,6 +180,12 @@ func NewLocalCache(startTs uint64) *LocalCache {
181180
}
182181
}
183182

183+
// NoCache returns a new LocalCache instance, which won't cache anything. Useful to pass startTs
184+
// around.
185+
func NoCache(startTs uint64) *LocalCache {
186+
return &LocalCache{startTs: startTs}
187+
}
188+
184189
func (lc *LocalCache) getNoStore(key string) *List {
185190
lc.RLock()
186191
defer lc.RUnlock()
@@ -205,8 +210,8 @@ func (lc *LocalCache) SetIfAbsent(key string, updated *List) *List {
205210
}
206211

207212
func (lc *LocalCache) getInternal(key []byte, readFromDisk bool) (*List, error) {
208-
if lc == nil {
209-
return getNew(key, pstore, math.MaxUint64)
213+
if lc.plists == nil {
214+
return getNew(key, pstore, lc.startTs)
210215
}
211216
skey := string(key)
212217
if pl := lc.getNoStore(skey); pl != nil {

worker/task.go

+3
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,9 @@ func processTask(ctx context.Context, q *pb.Query, gid uint32) (*pb.Result, erro
890890
if q.Cache == UseTxnCache {
891891
qs.cache = posting.Oracle().CacheAt(q.ReadTs)
892892
}
893+
if qs.cache == nil {
894+
qs.cache = posting.NoCache(q.ReadTs)
895+
}
893896
// For now, remove the query level cache. It is causing contention for queries with high
894897
// fan-out.
895898

0 commit comments

Comments
 (0)