mailgun / mailgun/groupcache

getgroup from different main instances will it work ?

Open
#58 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
539
Forks
76
PR merge metrics
No merged PRs in 30d

Description

` func NewGroupCacheHandler(cfg *viper.Viper) (*GroupCacheHandler, error) {
var (
endpoint = cfg.GetString("storage.kv.groupcache.endpoint")
ports = cfg.GetStringSlice("storage.kv.groupcache.ports")
cacheTTL = cfg.GetInt64("storage.kv.groupcache.cacheTTL")
cacheServers []*http.Server
group *groupcache.Group
)

var kvHandler KVHandler
var getterFunc groupcache.GetterFunc
kvType := cfg.GetString("storage.kv.groupcache.db")
getterFunc = func(ctx context.Context, key string, dest groupcache.Sink) error {

resp, err := kvHandler.Get(key)
if err != nil {
return err
}
if resp == nil {
return fmt.Errorf("key not found in etcd: %s", key)
}
jsonResp, _ := json.Marshal(resp)
dest.SetBytes(jsonResp, time.Now().Add(time.Duration(cacheTTL)*time.Minute))
return nil

}
switch kvType {
case "etcd":
etcdHandler, err := NewEtcdHandler(cfg)
if err != nil {
return nil, err
}
kvHandler = etcdHandler
case "badger":
badgerHandler, err := NewBadgerHandler(cfg)
if err != nil {
return nil, err
}
kvHandler = badgerHandler
default:
return nil, fmt.Errorf("unsupported kvType: %s", kvType)
}

pool := groupcache.NewHTTPPool("")
for _, port := range ports {
pool.Set("http://" + endpoint + ":" + port)
server := &http.Server{
Addr: endpoint + ":" + port,
Handler: pool,
}
cacheServers = append(cacheServers, server)
go func(srv *http.Server) {
log.Printf("Serving cache server %s \n", srv.Addr)
if err := srv.ListenAndServe(); err != nil {
log.Fatal(err)
}
}(server)
}

group = groupcache.GetGroup("data")
if group == nil {
fmt.Println("Error getting group from groupcache:")
group = groupcache.NewGroup("data", 3000000, getterFunc)
}

handler := &GroupCacheHandler{
KVHandler: kvHandler,
Group: group,
cacheTTL: cacheTTL,
}

return handler, nil
} `
I am running multiple main instances that use this function what I need is to be able to reach cache instance from another instance the problem is when am doing getgroup it doesn't work anyone have a solution?`

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with NewGroupCacheHandler and trace how groupcache.NewHTTPPool, pool.Set, and groupcache.GetGroup("data") behave when multiple main instances call the function. Reproduce the setup with multiple configured ports and instances, then determine whether one instance can retrieve a cache entry from another. Done means the cross-instance get behavior is demonstrated and the required configuration or code change is clearly identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.