You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Take Get as example,the inner tikvSnapshot code is:
func (s *tikvSnapshot) Get(ctx context.Context, k kv.Key) ([]byte, error) {
if s.interceptor != nil {
return s.interceptor.OnGet(ctx, NewSnapshot(s.KVSnapshot), k)
}
data, err := s.KVSnapshot.Get(ctx, k)
return data, extractKeyErr(err)
}
It means that if an interceptor is set, snapshot will delegate its read to the interceptor passing a kv.Snapshot parameter to it. Then the interceptor can do any thing to read the data.
For temporary table case, we can create a interceptor called TemporaryTableSnapshotInteceptor and its OnGet looks like this:
func (i *TemporaryTableSnapshotInteceptor) OnGet(ctx context.Context, snapshot kv.Snapshot, key kv.Key) ([]byte, error) {
if tblInfo, ok := i.getAccessTableInfoFromKey(key); ok {
if tblInfo.TempTableType == model.TempTableGlobal {
return nil, kv.ErrNotExist
}
if tblInfo.TempTableType == model.TempTableLocal {
val, err := i.memBuffer.Get(key)
if err == nil && len(val) == 0 {
return nil, kv.ErrNotExist
}
return val, err
}
}
// fallback to snapshot read if the key is not a temporary table key
return snapshot.Get(ctx, key)
}
It checks if it is accessing a temporary table's key. If it is, get data from memory otherwise fallback to default snapshot
The text was updated successfully, but these errors were encountered:
Considering comments in #27854 , we want some simpler implement for custom data retrieving in snapshot. The new implement have several considerations:
A preliminary proposal:
Firstly introduce a new interface
txn.SnapshotInterceptor
to snapshot. The definition is:We can set a interceptor to snapshot like this:
Take
Get
as example,the innertikvSnapshot
code is:It means that if an interceptor is set, snapshot will delegate its read to the interceptor passing a
kv.Snapshot
parameter to it. Then the interceptor can do any thing to read the data.For temporary table case, we can create a interceptor called
TemporaryTableSnapshotInteceptor
and itsOnGet
looks like this:It checks if it is accessing a temporary table's key. If it is, get data from memory otherwise fallback to default snapshot
The text was updated successfully, but these errors were encountered: