peering: add warning about AllowStaleRead (#13768)

This commit is contained in:
alex 2022-07-15 09:56:33 -07:00 committed by GitHub
parent 28bf578b2d
commit 5eaab0efcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 114 additions and 4 deletions

View File

@ -43,6 +43,11 @@ type ExampleReadTODO struct {
Value string
}
// @consul-rpc-glue: LeaderReadTODO
type ExampleLeaderReadTODO struct {
Value string
}
// @consul-rpc-glue: WriteTODO
type ExampleWriteTODO struct {
Value string

View File

@ -308,6 +308,50 @@ func (msg *ExampleReadTODO) Token() string {
return ""
}
// IsRead implements structs.RPCInfo
func (msg *ExampleLeaderReadTODO) IsRead() bool {
// TODO(peering): figure out read semantics here
return true
}
// AllowStaleRead implements structs.RPCInfo
func (msg *ExampleLeaderReadTODO) AllowStaleRead() bool {
// TODO(peering): figure out read semantics here
// TODO(peering): this needs to stay false for calls to head to the leader until we sync stream tracker information
// like ImportedServicesCount, ExportedServicesCount, as well as general Status fields thru raft to make available
// to followers as well
return false
}
// HasTimedOut implements structs.RPCInfo
func (msg *ExampleLeaderReadTODO) HasTimedOut(start time.Time, rpcHoldTimeout time.Duration, a time.Duration, b time.Duration) (bool, error) {
// TODO(peering): figure out read semantics here
return time.Since(start) > rpcHoldTimeout, nil
}
// Timeout implements structs.RPCInfo
func (msg *ExampleLeaderReadTODO) Timeout(rpcHoldTimeout time.Duration, a time.Duration, b time.Duration) time.Duration {
// TODO(peering): figure out read semantics here
return rpcHoldTimeout
}
// SetTokenSecret implements structs.RPCInfo
func (msg *ExampleLeaderReadTODO) SetTokenSecret(s string) {
// TODO(peering): figure out read semantics here
}
// TokenSecret implements structs.RPCInfo
func (msg *ExampleLeaderReadTODO) TokenSecret() string {
// TODO(peering): figure out read semantics here
return ""
}
// Token implements structs.RPCInfo
func (msg *ExampleLeaderReadTODO) Token() string {
// TODO(peering): figure out read semantics here
return ""
}
// IsRead implements structs.RPCInfo
func (msg *ExampleWriteTODO) IsRead() bool {
// TODO(peering): figure out write semantics here

View File

@ -108,6 +108,9 @@ func processFile(path string) error {
if ann.ReadTODO != "" {
log.Printf(" ReadTODO from %s", ann.ReadTODO)
}
if ann.LeaderReadTODO != "" {
log.Printf(" LeaderReadTODO from %s", ann.ReadTODO)
}
if ann.WriteTODO != "" {
log.Printf(" WriteTODO from %s", ann.WriteTODO)
}
@ -157,6 +160,9 @@ var _ time.Month
if typ.Annotation.Datacenter != "" {
buf.WriteString(fmt.Sprintf(tmplDatacenter, typ.Name, typ.Annotation.Datacenter))
}
if typ.Annotation.LeaderReadTODO != "" {
buf.WriteString(fmt.Sprintf(tmplLeaderOnlyReadTODO, typ.Name, typ.Annotation.ReadTODO))
}
if typ.Annotation.ReadTODO != "" {
buf.WriteString(fmt.Sprintf(tmplReadTODO, typ.Name, typ.Annotation.ReadTODO))
}
@ -266,6 +272,7 @@ type Annotation struct {
TargetDatacenter string
Datacenter string
ReadTODO string
LeaderReadTODO string
WriteTODO string
}
@ -319,6 +326,8 @@ func getAnnotation(doc []*ast.Comment) (Annotation, error) {
ann.ReadTODO = "ReadTODO"
case part == "WriteTODO":
ann.WriteTODO = "WriteTODO"
case part == "LeaderReadTODO":
ann.LeaderReadTODO = "LeaderReadTODO"
default:
return Annotation{}, fmt.Errorf("unexpected annotation part: %s", part)
@ -463,6 +472,52 @@ func (msg *%[1]s) Token() string {
}
`
const tmplLeaderOnlyReadTODO = `
// IsRead implements structs.RPCInfo
func (msg *%[1]s) IsRead() bool {
// TODO(peering): figure out read semantics here
return true
}
// AllowStaleRead implements structs.RPCInfo
func (msg *%[1]s) AllowStaleRead() bool {
// TODO(peering): figure out read semantics here
// TODO(peering): this needs to stay false for calls to head to the leader until we sync stream tracker information
// like ImportedServicesCount, ExportedServicesCount, as well as general Status fields thru raft to make available
// to followers as well
return false
}
// HasTimedOut implements structs.RPCInfo
func (msg *%[1]s) HasTimedOut(start time.Time, rpcHoldTimeout time.Duration, a time.Duration, b time.Duration) (bool, error) {
// TODO(peering): figure out read semantics here
return time.Since(start) > rpcHoldTimeout, nil
}
// Timeout implements structs.RPCInfo
func (msg *%[1]s) Timeout(rpcHoldTimeout time.Duration, a time.Duration, b time.Duration) time.Duration {
// TODO(peering): figure out read semantics here
return rpcHoldTimeout
}
// SetTokenSecret implements structs.RPCInfo
func (msg *%[1]s) SetTokenSecret(s string) {
// TODO(peering): figure out read semantics here
}
// TokenSecret implements structs.RPCInfo
func (msg *%[1]s) TokenSecret() string {
// TODO(peering): figure out read semantics here
return ""
}
// Token implements structs.RPCInfo
func (msg *%[1]s) Token() string {
// TODO(peering): figure out read semantics here
return ""
}
`
const tmplReadTODO = `
// IsRead implements structs.RPCInfo
func (msg *%[1]s) IsRead() bool {

View File

@ -379,7 +379,7 @@ func (x *PeeringTrustBundle) GetModifyIndex() uint64 {
return 0
}
// @consul-rpc-glue: Datacenter,ReadTODO
// @consul-rpc-glue: Datacenter,LeaderReadTODO
type PeeringReadRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -490,7 +490,7 @@ func (x *PeeringReadResponse) GetPeering() *Peering {
return nil
}
// @consul-rpc-glue: Datacenter,ReadTODO
// @consul-rpc-glue: Datacenter,LeaderReadTODO
type PeeringListRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache

View File

@ -136,7 +136,7 @@ message PeeringTrustBundle {
uint64 ModifyIndex = 7;
}
// @consul-rpc-glue: Datacenter,ReadTODO
// @consul-rpc-glue: Datacenter,LeaderReadTODO
message PeeringReadRequest {
string Name = 1;
string Partition = 2;
@ -152,7 +152,7 @@ message PeeringReadResponse {
//TODO(peering) query metadata
}
// @consul-rpc-glue: Datacenter,ReadTODO
// @consul-rpc-glue: Datacenter,LeaderReadTODO
message PeeringListRequest {
string Partition = 1;

View File

@ -29,6 +29,9 @@ func (msg *PeeringReadRequest) IsRead() bool {
// AllowStaleRead implements structs.RPCInfo
func (msg *PeeringReadRequest) AllowStaleRead() bool {
// TODO(peering): figure out read semantics here
// TODO(peering): this needs to stay false for calls to head to the leader until we sync stream tracker information
// like ImportedServicesCount, ExportedServicesCount, as well as general Status fields thru raft to make available
// to followers as well
return false
}
@ -78,6 +81,9 @@ func (msg *PeeringListRequest) IsRead() bool {
// AllowStaleRead implements structs.RPCInfo
func (msg *PeeringListRequest) AllowStaleRead() bool {
// TODO(peering): figure out read semantics here
// TODO(peering): this needs to stay false for calls to head to the leader until we sync stream tracker information
// like ImportedServicesCount, ExportedServicesCount, as well as general Status fields thru raft to make available
// to followers as well
return false
}