Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/common/scripts/vtctld-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ vtctld \
--pprof-http \
> $VTDATAROOT/tmp/vtctld.out 2>&1 &

echo "Curling \"http://${hostname}:${vtctld_web_port}/debug/status\" to check if vtctld is up"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it not the same thing we do from line 41 to 47?

Copy link
Copy Markdown
Collaborator

@deepthi deepthi Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just adding an echo so that we can see how far the script got, and where it might be stuck, if at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes Deepthi is correct - just a sanity check that vtctld client was initiated, and we're moving onto curling now! 😄


for _ in {0..300}; do
curl -I "http://${hostname}:${vtctld_web_port}/debug/status" &>/dev/null && break
sleep 0.1
Expand Down
11 changes: 8 additions & 3 deletions go/vt/vtadmin/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"sync"
"time"

"github.com/patrickmn/go-cache"
cache "github.com/patrickmn/go-cache"

"vitess.io/vitess/go/vt/log"
)
Expand Down Expand Up @@ -161,8 +161,13 @@ func (c *Cache[Key, Value]) add(key string, val Value, d time.Duration) error {
c.lastFill[key] = time.Now().UTC()
c.m.Unlock()

// Then cache the actual value.
return c.cache.Add(key, val, d)
_, expr, exists := c.cache.GetWithExpiration(key)
if exists && (expr.IsZero() || expr.After(time.Now())) {
return c.cache.Replace(key, val, d)
} else {
// Then cache the actual value.
return c.cache.Add(key, val, d)
}
}

// Get returns the Value stored for the key, if present in the cache. If the key
Expand Down
45 changes: 45 additions & 0 deletions go/vt/vtadmin/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,48 @@ func TestEnqueueBackfillTimeout(t *testing.T) {
assert.Equal(t, q.shouldFail, !ok, "enqueue should %s wait timeout", q.msg)
}
}

func TestUpsertCacheKey(t *testing.T) {
var callcount int
c := cache.New(func(ctx context.Context, req intkey) (any, error) {
time.Sleep(time.Millisecond * 50) // make fills take time so that the second enqueue exceeds WaitTimeout
callcount++
return nil, nil
}, cache.Config{
BackfillEnqueueWaitTime: time.Millisecond * 10,
})

var inserts = []struct {
shouldFail bool
msg string
key intkey
val any
expectedVal any
duration time.Duration
}{
{
shouldFail: false,
key: intkey(1),
val: "Old Value",
msg: "first add should succeed",
expectedVal: "Old Value",
},
{
shouldFail: false,
key: intkey(1),
val: "New Value",
msg: "second update should succeed",
expectedVal: "New Value",
},
}
for _, tt := range inserts {
err := c.Add(tt.key, tt.val, tt.duration)
if !tt.shouldFail {
assert.Nil(t, err)
}

val, exists := c.Get(tt.key)
assert.True(t, exists)
assert.Equal(t, val, tt.expectedVal)
}
}
Loading