diff --git a/Makefile b/Makefile index b49d262..d343a96 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ all: lint test build .PHONY: build # make build, Build the binary file build: wire - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -ldflags ${ldflags} -o bin/$(SERVICE_NAME) cmd/server/main.go cmd/server/wire_gen.go + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -race -ldflags ${ldflags} -o bin/$(SERVICE_NAME) cmd/server/main.go cmd/server/wire_gen.go # CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -ldflags ${ldflags} -o bin/$(SERVICE_NAME)-consumer cmd/consumer/main.go cmd/consumer/wire_gen.go .PHONY: run @@ -75,7 +75,7 @@ lint: .PHONY: test # make test test: vet - @go test -short ${PKG_LIST} + @go test -race -short ${PKG_LIST} .PHONY: vet # make vet diff --git a/api/user/v1/user.pb.go b/api/user/v1/user.pb.go index 27d2336..8c8a1e1 100644 --- a/api/user/v1/user.pb.go +++ b/api/user/v1/user.pb.go @@ -6,6 +6,7 @@ package v1 import ( fmt "fmt" _ "github.com/envoyproxy/protoc-gen-validate/validate" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" _ "google.golang.org/genproto/googleapis/api/annotations" io "io" @@ -1283,74 +1284,75 @@ func init() { func init() { proto.RegisterFile("api/user/v1/user.proto", fileDescriptor_68a8f9c10c733b91) } var fileDescriptor_68a8f9c10c733b91 = []byte{ - // 1063 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x57, 0xcd, 0x6f, 0xe3, 0x44, - 0x14, 0x5f, 0x3b, 0x6d, 0x3e, 0x5e, 0x9a, 0x8f, 0x9d, 0xa6, 0xad, 0xd7, 0xb4, 0x55, 0x77, 0x7a, - 0x09, 0x45, 0xad, 0xd5, 0x72, 0x62, 0x57, 0x1c, 0x5a, 0x28, 0x2b, 0x44, 0x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, 0x33, 0x89, - 0x69, 0x43, 0xe2, 0x57, 0xcd, 0x52, 0x82, 0x8f, 0xc8, 0x13, 0xa8, 0xde, 0x6d, 0x5a, 0xb2, 0x9f, - 0x41, 0xc8, 0x0c, 0x18, 0x73, 0xf7, 0x95, 0x7a, 0x64, 0xd9, 0x93, 0x2c, 0x3b, 0x94, 0xa4, 0x6f, - 0x11, 0xcf, 0x8d, 0x47, 0xda, 0xd1, 0xc5, 0xbb, 0xdf, 0xdf, 0xee, 0x6b, 0x3f, 0xdc, 0xee, 0x6b, - 0x3f, 0xdd, 0xee, 0x6b, 0xcf, 0xad, 0xa1, 0x23, 0x46, 0xb3, 0xfe, 0xc9, 0xc0, 0x9b, 0x58, 0x43, - 0xef, 0x98, 0x33, 0xfc, 0xf8, 0x97, 0x7f, 0x8f, 0xc7, 0x6c, 0xe1, 0xcd, 0x84, 0xa5, 0xfc, 0x94, - 0x78, 0x3c, 0x3f, 0xed, 0xe7, 0xe5, 0x2f, 0x81, 0xb7, 0xff, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x2e, - 0x85, 0xb8, 0xad, 0x63, 0x0c, 0x00, 0x00, + // 1075 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x57, 0xcd, 0x4f, 0x24, 0x45, + 0x14, 0xdf, 0xee, 0x81, 0xf9, 0x78, 0xc3, 0x7c, 0x50, 0x0c, 0xd0, 0xdb, 0x02, 0x61, 0x8b, 0xcb, + 0x88, 0x81, 0x0e, 0x78, 0x72, 0x37, 0x1e, 0x40, 0x71, 0x63, 0x64, 0x59, 0x33, 0x40, 0xd4, 0xbd, + 0x60, 0xcd, 0x74, 0xd1, 0xd3, 0xd9, 0xa1, 0x6b, 0xec, 0xae, 0x19, 0x82, 0xc6, 0x8b, 0xff, 0x81, + 0xf1, 0x9f, 0xf2, 0x68, 0xe2, 0x3f, 0x60, 0x88, 0x07, 0xe3, 0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0x4b, 0x36, 0x0a, 0x08, 0x85, 0x01, + 0x63, 0xaf, 0xbd, 0x52, 0x8f, 0x2c, 0xeb, 0x8a, 0x65, 0x95, 0x92, 0xfc, 0x2d, 0xd2, 0xb9, 0xf1, + 0xd8, 0xd8, 0x3e, 0x7c, 0xf7, 0xfb, 0xdb, 0x0d, 0xe3, 0x87, 0xdb, 0x0d, 0xe3, 0xa7, 0xdb, 0x0d, + 0xe3, 0x85, 0xe3, 0xf9, 0x72, 0x38, 0xe9, 0xef, 0x0e, 0xc4, 0x95, 0xe3, 0x89, 0x1d, 0xce, 0xf0, + 0xb3, 0x40, 0xfd, 0xdd, 0x19, 0xb1, 0x1b, 0x31, 0x91, 0x8e, 0xf6, 0x91, 0xf1, 0x64, 0xba, 0xd7, + 0x2f, 0xab, 0x2f, 0x81, 0xb7, 0xff, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x73, 0x7d, 0x0e, 0xf1, 0x7d, + 0x0c, 0x00, 0x00, } func (m *User) Marshal() (dAtA []byte, err error) { diff --git a/api/user/v1/user.proto b/api/user/v1/user.proto index 972c3a5..7683dbc 100644 --- a/api/user/v1/user.proto +++ b/api/user/v1/user.proto @@ -4,6 +4,7 @@ package user.v1; import "validate/validate.proto"; import "google/api/annotations.proto"; +import "gogo/protobuf/gogo.proto"; option go_package = "github.com/go-eagle/eagle-layout/api/user/v1;v1"; @@ -190,6 +191,7 @@ message GetUserReply { message BatchGetUsersRequest { repeated int64 ids = 1; + // int64 ids = 1 [(gogoproto.moretags) = 'form:"ids"']; } message BatchGetUsersReply { diff --git a/api/user/v1/user_gin.pb.go b/api/user/v1/user_gin.pb.go index dd22331..ea08a49 100644 --- a/api/user/v1/user_gin.pb.go +++ b/api/user/v1/user_gin.pb.go @@ -9,7 +9,7 @@ import ( gin "github.com/gin-gonic/gin" app "github.com/go-eagle/eagle/pkg/app" errcode "github.com/go-eagle/eagle/pkg/errcode" - "github.com/go-eagle/eagle/pkg/utils" + "github.com/spf13/cast" metadata "google.golang.org/grpc/metadata" ) @@ -141,8 +141,7 @@ func (s *UserService) GetUser_0(ctx *gin.Context) { } // make sure the uri include :id - id, _ := utils.StringToInt64(ctx.Param("id")) - in.Id = id + in.Id = cast.ToInt64(ctx.Param("id")) md := metadata.New(nil) for k, v := range ctx.Request.Header { diff --git a/cmd/gen/generate.go b/cmd/gen/generate.go index c6dd95c..63dc162 100644 --- a/cmd/gen/generate.go +++ b/cmd/gen/generate.go @@ -47,10 +47,13 @@ func main() { dal.Init() g := gen.NewGenerator(gen.Config{ - OutPath: "./internal/dal/db/dao", // 生成的查询类代码的输出路径,默认./query, 这里改为dao - ModelPkgPath: "./internal/dal/db/model", // 默认情况下会跟随OutPath参数,在同目录下生成model目录 - Mode: gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode - WithUnitTest: true, // 为生成的查询类代码生成单元测试 + OutPath: "./internal/dal/db/dao", // 生成的查询类代码的输出路径,默认./query, 这里改为dao + ModelPkgPath: "./internal/dal/db/model", // 默认情况下会跟随OutPath参数,在同目录下生成model目录 + Mode: gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode + WithUnitTest: true, // 为生成的查询类代码生成单元测试 + FieldNullable: true, // 对于数据库中nullable的数据,在生成代码中自动对应为指针类型 + FieldWithIndexTag: true, // 从数据库同步的表结构代码包含gorm的index tag + FieldWithTypeTag: true, // 同步的表结构代码包含gorm的type tag(数据库中对应数据类型) }) g.UseDB(dal.DB) // reuse your gorm db diff --git a/internal/dal/cache/user_cache.go b/internal/dal/cache/user_cache.go index 7761dc0..6db3acf 100644 --- a/internal/dal/cache/user_cache.go +++ b/internal/dal/cache/user_cache.go @@ -70,7 +70,7 @@ func (c *userCache) GetUserCache(ctx context.Context, id int64) (data *model.Use cacheKey := c.GetUserCacheKey(id) err = c.cache.Get(ctx, cacheKey, &data) if err != nil && !errors.Is(err, redis.Nil) { - log.WithContext(ctx).Warnf("get err from redis, err: %v", err) + log.WithContext(ctx).Warnf("[cache] GetUserCache err: %v", err) return nil, err } return data, nil diff --git a/internal/repository/README.md b/internal/repository/README.md index 1c680f8..e4a2a88 100644 --- a/internal/repository/README.md +++ b/internal/repository/README.md @@ -19,4 +19,4 @@ / | \ / | \ db rpc cache -``` +``` \ No newline at end of file diff --git a/internal/repository/user_repo.go b/internal/repository/user_repo.go index da8e0a9..0b27bbd 100644 --- a/internal/repository/user_repo.go +++ b/internal/repository/user_repo.go @@ -6,10 +6,13 @@ import ( "context" "time" + localCache "github.com/go-eagle/eagle/pkg/cache" + "github.com/go-eagle/eagle/pkg/encoding" "github.com/pkg/errors" "github.com/spf13/cast" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/trace" + "golang.org/x/sync/singleflight" "gorm.io/gorm" "github.com/go-eagle/eagle-layout/internal/dal" @@ -32,17 +35,21 @@ type UserRepo interface { } type userRepo struct { - db *dal.DBClient - tracer trace.Tracer - cache cache.UserCache + db *dal.DBClient + tracer trace.Tracer + cache cache.UserCache + localCache localCache.Cache + sg singleflight.Group } // NewUser new a repository and return func NewUserRepo(db *dal.DBClient, cache cache.UserCache) UserRepo { return &userRepo{ - db: db, - tracer: otel.Tracer("user"), - cache: cache, + db: db, + tracer: otel.Tracer("user"), + cache: cache, + localCache: localCache.NewMemoryCache("local:user:", encoding.JSONEncoding{}), + sg: singleflight.Group{}, } } @@ -69,32 +76,59 @@ func (r *userRepo) UpdateUser(ctx context.Context, id int64, data model.UserInfo // GetUser get a record func (r *userRepo) GetUser(ctx context.Context, id int64) (ret *model.UserInfoModel, err error) { - // read cache - item, err := r.cache.GetUserCache(ctx, id) + // get data from local cache + err = r.localCache.Get(ctx, cast.ToString(id), &ret) if err != nil { return nil, err } - if item != nil { - return item, nil + if ret != nil && ret.ID > 0 { + return ret, nil } - // read db - data, err := dao.UserInfoModel.WithContext(ctx).Where(dao.UserInfoModel.ID.Eq(id)).First() + // read redis cache + ret, err = r.cache.GetUserCache(ctx, id) if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - r.cache.SetCacheWithNotFound(ctx, id) - } - return + return nil, err + } + if ret != nil && ret.ID > 0 { + return ret, nil } - // write cache - if data != nil && data.ID > 0 { - err = r.cache.SetUserCache(ctx, id, data, 5*time.Minute) + // get data from db + // 避免缓存击穿(瞬间有大量请求过来) + val, err, _ := r.sg.Do("sg:user:"+cast.ToString(id), func() (interface{}, error) { + // read db or rpc + data, err := dao.UserInfoModel.WithContext(ctx).Where(dao.UserInfoModel.ID.Eq(id)).First() if err != nil { - return nil, err + // cache not found and set empty cache to avoid 缓存穿透 + // Note: 如果缓存空数据太多,会大大降低缓存命中率,可以改为使用布隆过滤器 + if errors.Is(err, gorm.ErrRecordNotFound) { + r.cache.SetCacheWithNotFound(ctx, id) + } + return nil, errors.Wrapf(err, "[repo] GetUser get User from db error, id: %d", id) } + + // write cache + if data != nil && data.ID > 0 { + // write redis + err = r.cache.SetUserCache(ctx, id, data, 5*time.Minute) + if err != nil { + return nil, errors.WithMessage(err, "[repo] GetUser SetUserCache error") + } + + // write local cache + err = r.localCache.Set(ctx, cast.ToString(id), data, 2*time.Minute) + if err != nil { + return nil, errors.WithMessage(err, "[repo] GetUser localCache set error") + } + } + return data, nil + }) + if err != nil { + return nil, err } - return data, nil + + return val.(*model.UserInfoModel), nil } // BatchGetUser batch get items