@@ -547,9 +547,16 @@ func (g *group) lookupCache(key string) (value transport.ByteView, ok bool) {
547
547
return
548
548
}
549
549
550
+ func (g * group ) isOwner (key string ) bool {
551
+ // PickPeer devuelve (cliente, isRemote)
552
+ // Si isRemote == false, este nodo es el dueño.
553
+ _ , remote := g .instance .PickPeer (key )
554
+ return ! remote
555
+ }
556
+
550
557
// RemoteSet is called by the transport to set values in the local and hot caches when
551
558
// a remote peer sends us a pb.SetRequest
552
- func (g * group ) RemoteSet (key string , value []byte , expire time.Time ) {
559
+ /* func (g *group) RemoteSet(key string, value []byte, expire time.Time) {
553
560
if g.maxCacheBytes <= 0 {
554
561
return
555
562
}
@@ -566,6 +573,29 @@ func (g *group) RemoteSet(key string, value []byte, expire time.Time) {
566
573
// It's possible the value could be in the hot cache.
567
574
g.hotCache.Remove(key)
568
575
})
576
+ }*/
577
+
578
+ func (g * group ) RemoteSet (key string , value []byte , expire time.Time ) {
579
+ if g .maxCacheBytes <= 0 {
580
+ return
581
+ }
582
+
583
+ // Construimos el ByteView una sola vez
584
+ bv := transport .ByteViewWithExpire (value , expire )
585
+
586
+ // Bloqueamos los Gets mientras actualizamos las cachés locales
587
+ g .loadGroup .Lock (func () {
588
+ if g .isOwner (key ) {
589
+ // Este nodo es el propietario ► almacena en mainCache
590
+ g .mainCache .Add (key , bv )
591
+ // Por si la clave ya estaba de paso en hotCache
592
+ g .hotCache .Remove (key )
593
+ } else {
594
+ // Nodo no-dueño ► replica en hotCache (límite 1/8)
595
+ g .hotCache .Add (key , bv )
596
+ // Nunca la guardamos en mainCache aquí
597
+ }
598
+ })
569
599
}
570
600
571
601
func (g * group ) LocalRemove (key string ) {
0 commit comments