Build influxdb on Debian get too many errors - compilation

When I build on Kali Linux, I get some errors.
OS info:
Linux kali 5.16.0-kali7-amd64 #1 SMP PREEMPT Debian 5.16.18-1kali1 (2022-04-01) x86_64 GNU/Linux
go version go1.18.4 linux/amd64
$ git clone https://github.com/influxdata/influxdb.git
$ make
error info:
pkg/tracing/spancontext.go:16:23: cannot use &wire.SpanContext{…} (value of type *wire.SpanContext) as type protoreflect.ProtoMessage in argument to proto.Marshal:
*wire.SpanContext does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
pkg/tracing/spancontext.go:24:31: cannot use &ws (value of type *wire.SpanContext) as type protoreflect.ProtoMessage in argument to proto.Unmarshal:
*wire.SpanContext does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
pkg/tracing/trace_encoding.go:80:23: cannot use &wt (value of type *wire.Trace) as type protoreflect.ProtoMessage in argument to proto.Marshal:
*wire.Trace does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
pkg/tracing/trace_encoding.go:116:34: cannot use &wt (value of type *wire.Trace) as type protoreflect.ProtoMessage in argument to proto.Unmarshal:
*wire.Trace does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
github.com/influxdata/influxdb/v2/influxql/query
influxql/query/iterator.gen.go:2631:29: cannot use encodeFloatPoint(p) (value of type *"github.com/influxdata/influxdb/v2/influxql/query/internal".Point) as type protoreflect.ProtoMessage in argument to proto.Marshal:
*"github.com/influxdata/influxdb/v2/influxql/query/internal".Point does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
influxql/query/iterator.gen.go:5295:29: cannot use encodeIntegerPoint(p) (value of type *"github.com/influxdata/influxdb/v2/influxql/query/internal".Point) as type protoreflect.ProtoMessage in argument to proto.Marshal:
*"github.com/influxdata/influxdb/v2/influxql/query/internal".Point does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
influxql/query/iterator.gen.go:7959:29: cannot use encodeUnsignedPoint(p) (value of type *"github.com/influxdata/influxdb/v2/influxql/query/internal".Point) as type protoreflect.ProtoMessage in argument to proto.Marshal:
*"github.com/influxdata/influxdb/v2/influxql/query/internal".Point does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
influxql/query/iterator.gen.go:10609:29: cannot use encodeStringPoint(p) (value of type *"github.com/influxdata/influxdb/v2/influxql/query/internal".Point) as type protoreflect.ProtoMessage in argument to proto.Marshal:
*"github.com/influxdata/influxdb/v2/influxql/query/internal".Point does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
influxql/query/iterator.gen.go:13259:29: cannot use encodeBooleanPoint(p) (value of type *"github.com/influxdata/influxdb/v2/influxql/query/internal".Point) as type protoreflect.ProtoMessage in argument to proto.Marshal:
*"github.com/influxdata/influxdb/v2/influxql/query/internal".Point does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
influxql/query/iterator.go:930:23: cannot use encodeIteratorOptions(opt) (value of type *"github.com/influxdata/influxdb/v2/influxql/query/internal".IteratorOptions) as type protoreflect.ProtoMessage in argument to proto.Marshal:
*"github.com/influxdata/influxdb/v2/influxql/query/internal".IteratorOptions does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
influxql/query/iterator.go:936:33: cannot use &pb (value of type *"github.com/influxdata/influxdb/v2/influxql/query/internal".IteratorOptions) as type protoreflect.ProtoMessage in argument to proto.Unmarshal:
*"github.com/influxdata/influxdb/v2/influxql/query/internal".IteratorOptions does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
influxql/query/iterator.go:1357:28: cannot use &internal.Point{…} (value of type *"github.com/influxdata/influxdb/v2/influxql/query/internal".Point) as type protoreflect.ProtoMessage in argument to proto.Marshal:
*"github.com/influxdata/influxdb/v2/influxql/query/internal".Point does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
influxql/query/point.gen.go:170:28: cannot use encodeFloatPoint(p) (value of type *"github.com/influxdata/influxdb/v2/influxql/query/internal".Point) as type protoreflect.ProtoMessage in argument to proto.Marshal:
*"github.com/influxdata/influxdb/v2/influxql/query/internal".Point does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
influxql/query/point.gen.go:219:34: cannot use &pb (value of type *"github.com/influxdata/influxdb/v2/influxql/query/internal".Point) as type protoreflect.ProtoMessage in argument to proto.Unmarshal:
*"github.com/influxdata/influxdb/v2/influxql/query/internal".Point does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
influxql/query/point.gen.go:219:34: too many errors
make: *** [GNUmakefile:84:bin/linux/influxd]

Related

How to embed third party types in Go?

In my application, the Decimal package github.com/shopspring/decimal is used.
In order to write custom functions on the decimal.Decimal type, I have created my own Decimal type and embedded decimal.Decimal:
type Decimal struct {
decimal.Decimal
}
This works great, and I can now access decimal.Decimal methods on Decimal object:
a := Decimal{decimal.NewFromFloat(1.0)}
b := Decimal{a.Neg()}
Some of decimal.Decimal methods requires an argument of type decimal.Decimal, f.ex:
c := Decimal{a.Add(b)}
The above line cannot compile because of error: cannot use b (variable of type Decimal) as decimal.Decimal value in argument to a.Add
I have tried to convert Decimal to decimal.Decimal:
c := Decimal{a.Add((decimal.Decimal)(b))}
The above code would not compile due to below error:
cannot convert b (variable of type Decimal) to decimal.Decimal
Question: How to extend/embed a third party type in a way that allows the use of "parent" methods and can use the extended type as argument in methods that requires argument of parents type?
A field declared with a type but no explicit field name is called an embedded field. An embedded field must be specified as a type name T or as a pointer to a non-interface type name *T, and T itself may not be a pointer type. The unqualified type name acts as the field name.
So a quick and dirty solution would be to simply access the field using the "unqualified type name".
_ = Decimal{a.Add(b.Decimal)}
If, however, you're looking for a more seamless experience when using the new type, then your only option is to redeclare the methods that require the original type and use the new type in its place. These redeclared methods need only be simple wrappers that pass the embedded field of one instance to the method of the embedded field of the other instance. For example:
type Time struct {
time.Time
}
func (t Time) In(loc *time.Location) Time {
return Time{t.Time.In(loc)}
}
func (t Time) Equal(u Time) bool {
return t.Time.Equal(u.Time)
}

I want to create interface for dig

I'm a novice in golang.
I want to abstract from the implementation of the service container:
type Container interface {
Provide(constructor interface{}, opts ...interface{}) error
Invoke(function interface{}, opts ...interface{}) error
}
but an error occurs:
#13 0.387 cmd/app/main.go:26:40: cannot use container (type *dig.Container) as type application.Container in argument to application.NewApplication:
#13 0.387 *dig.Container does not implement application.Container (wrong type for Invoke method)
#13 0.387 have Invoke(interface {}, ...dig.InvokeOption) error
#13 0.387 want Invoke(interface {}, ...interface {}) error
What am I doing wrong?
How I can declare interface correct?
Cannot use container (type *dig.Container) as type application.Container in argument to application.NewApplication:
*dig.Container does not implement application.Container (wrong type for Invoke method)
have Invoke(interface {}, ...dig.InvokeOption) error
want Invoke(interface {}, ...interface {}) error
This means *dig.Container doesn't satisfy the interface application.Container. It goes on to explain that application.Container requires the Invoke method to take a variadic list of interface{}, but *dig.Container takes a variadic list of dig.InvokeOption.
Even though an empty interface can store any type, that does not mean that any slice type is automatically also a slice of empty interfaces (That's a big motivation for Generics, which should come out soon).
I remember being confused by this myself. Consder this code:
package main
import (
"fmt"
)
type T struct{}
func main() {
var Ts = []T{
T{}, T{}, T{},
}
fmt.Println(Ts...)
}
It will not compile, even thought each individual T satisfies interface{} because a []T is not an []interface{}:
./prog.go:13:16: cannot use Ts (type []T) as type []interface {} in argument to fmt.Println
The easiest solution here would be to make dig.Container's Invoke function match the Invoke signature of application.Container. You can still pass it a list of *dig.InvokeOptions, which individually satisfy interface{}. You'll still have to convert the interface{}s back to *dig.InvokeOptions within dig.Container.Invoke.

Getting the base type of a custom type using Reflect

Say I create a custom type in Go:
type CustomTime time.Time
Using reflection, I'm comparing types, e.g.
var foo CustomTime = CustomTime(time.Now())
customType := reflect.TypeOf(foo)
timeType := reflect.TypeOf(time.Now())
if customType == timeType {
fmt.Println("Is timeType")
} else {
fmt.Println("Is not timeType")
}
This prints "Is not timeType". What I'm trying to do is find a way to see if the base type that the custom type uses (i.e. the time.Time in type CustomType time.Time) is of type time.Time.
I've tried using reflect's Kind() function, but that returns struct for both since time.Time is a struct.
Here's a playground with this code.
You can't exactly, because that's not how types work in Go. In your example, CustomTime's underlying type isn't Time; both CustomTime and time.Time share the same underlying type, which is a struct type. From the docs:
Each type T has an underlying type: If T is one of the predeclared boolean, numeric, or string types, or a type literal, the corresponding underlying type is T itself. Otherwise, T's underlying type is the underlying type of the type to which T refers in its type declaration.
That means that CustomTimes underlying type isn't time.Time, it's time.Time's underlying type.
You can use reflect.Type's ConvertibleTo() method to see if one type is convertible to another, which is as close as you're likely to get to what you're describing.

Are there official words about what type is an interface type in Go?

This is a Go grammar question and seems a stupid question but I've been checking the Go language specification to find some official words or definitions to define what type is a xxx type, say, what type is an interface type?
For example, I see words like these:
The method set of an interface type is its interface.
Or
An embedded field must be specified as a type name T or as a pointer to a non-interface type name *T, and T itself may not be a pointer type.
Or
Consider a struct type T with two methods ...
type T struct {
a int
}
....
A type literal like struct {...} is a struct type, what about A in
type A struct {...} and B in type B interface{...}? Is A a struct type and B an interface type?
Yes, from the above sample for the struct type T, I can tell that a defined type (by the "type" declaration) whose given type is a struct type or interface type is also a struct or interface type. So A is a struct type and B is an interface type also. But where are the official definitions of this rule?
For defined types I can only find the following relating to type categories:
A type definition creates a new, distinct type with the same underlying type and operations as the given type, and binds an identifier to it.
So my understanding is that the defined type is a new, distinct type with the given type, but they are in the same type category, say, interface types or struct types. Still, there are no such definitions.
TLDR;
The kind of type T is interface if its underlying type is an interface type.
The kind of type T is struct if its underlying type is a struct type.
Spec: Struct types and Spec: Interface types specifies exactly what are the struct and interface types:
StructType = "struct" "{" { FieldDecl ";" } "}" .
FieldDecl = (IdentifierList Type | EmbeddedField) [ Tag ] .
EmbeddedField = [ "*" ] TypeName .
Tag = string_lit .
InterfaceType = "interface" "{" { MethodSpec ";" } "}" .
MethodSpec = MethodName Signature | InterfaceTypeName .
MethodName = identifier .
InterfaceTypeName = TypeName .
So for example these are struct types:
struct { A int }
struct {}
struct { _ int }
and these are interface types:
interface { String() string }
interface {}
We may use a type declaration to create a new type, such as:
type Point struct { X, Y int }
The above type definition creates a new, distinct type with the same underlying type and operations as the given type, and binds an identifier to it. The definition of underlying type is recursive:
Each type T has an underlying type: If T is one of the predeclared boolean, numeric, or string types, or a type literal, the corresponding underlying type is T itself. Otherwise, T's underlying type is the underlying type of the type to which T refers in its type declaration.
When we talk about arbitrary types being structs or interfaces, we're talking about their kind.
In the light of this, basically your question is equivalent to this:
"When is the kind of an arbitrary type interface or struct?"
The answer to this question is not in the spec, but this is how we could define it:
The kind of a type T is interface if its underlying type is an interface type.
Similarly:
The kind of a type T is struct if its underlying type is a struct type.
So for example:
type Point struct { X, Y int }
type PP Point
Is the type struct { X, Y int } of kind struct? Yes, because since it's a type literal, its underlying type is itself, and it's by definition a struct type.
Is Point a struct? Since the underlying type of Point is the underlying type of the type to which it refers in its type declaration, which is a type literal (see above), it is of struct type (its kind is struct).
Is PP a struct? Since its underlying type is the underlying type of the type to which it refers in its type declaration (which is Point), whose underlying type is a struct type literal, yes, it is also a struct type.
This kind we're talking about is represented by the reflect.Kind type. There are reflect.Interface and reflect.Struct constants (of type reflect.Kind) to represent the struct and interface kinds. And the reflect.Type type descriptor has a Type.Kind() method to access this kind.
This is how you can check if the type (kind) of some value is a struct for example:
func isStruct(i interface{}) bool {
return reflect.TypeOf(i).Kind() == reflect.Struct
}
Testing it (try it on the Go Playground):
fmt.Println(isStruct(Point{})) // true
fmt.Println(isStruct(PP{})) // true
fmt.Println(isStruct(struct{}{})) // true
fmt.Println(isStruct("text")) // false
Checking for interface type is a little more complicated because passing an interface value to a function that expects interface{} will not pass the interface value as-is but the concrete value "stored" in it, and as an interface{} value. We would have to pass a pointer to interface (which otherwise rarely makes sense in Go), access the element type and check its kind. For details, see this answer: What is the difference between reflect.ValueOf() and Value.Elem() in go?
An interface type is a type introduced by the interface keyword, or a name for such a type as defined by type name interface (plus of course the actual requirements for that interface).
Any type, whether it is an interface type or not, implements an interface type if it has the appropriate set of named methods. That is, a struct type may be sufficient to be used with some interface type. Even a non-struct type may be sufficient:
type foo int
func (receiver_arg foo) method1() { ... }
Type-name foo now implements any interface that requires a method named method1 (provided of course that it implements the rest of any required methods).
... the defined type [via the type keyword] is a new, distinct type with the given type, but they are in the same type category ...
Yes, just so. Using reflect, you'll find that they have the same Kind. The word kind isn't in the spec like this but it's quite useful, and the link here enumerates all the fundamental type-kinds in Go.

Is gcc's atomic test and set builtin the same as an atomic fetch and store operation?

I came across an atomic "fetch and store" instruction in the description of an MCS lock.
From what I gather, this atomically writes a value to a memory location and returns the original value of that memory location, is that correct?
And is gcc's atomic builtin,
__sync_lock_test_and_set
the same as an atomic fetch and store?
Per the GCC info page, this is indeed atomic, but it's not the basic atomic fetch and store.
(this is clipped from the 4.4 manual, so different section number)
5.48 Built-in functions for atomic memory access
(...)
TYPE __sync_fetch_and_add (TYPE *ptr, TYPE value, ...)
TYPE __sync_fetch_and_sub (TYPE *ptr, TYPE value, ...)
TYPE __sync_fetch_and_or (TYPE *ptr, TYPE value, ...)
TYPE __sync_fetch_and_and (TYPE *ptr, TYPE value, ...)
TYPE __sync_fetch_and_xor (TYPE *ptr, TYPE value, ...)
TYPE __sync_fetch_and_nand (TYPE *ptr, TYPE value, ...)
TYPE __sync_add_and_fetch (TYPE *ptr, TYPE value, ...)
TYPE __sync_sub_and_fetch (TYPE *ptr, TYPE value, ...)
TYPE __sync_or_and_fetch (TYPE *ptr, TYPE value, ...)
TYPE __sync_and_and_fetch (TYPE *ptr, TYPE value, ...)
TYPE __sync_xor_and_fetch (TYPE *ptr, TYPE value, ...)
TYPE __sync_nand_and_fetch (TYPE *ptr, TYPE value, ...)
bool __sync_bool_compare_and_swap (TYPE *ptr, TYPE oldval TYPE newval, ...)
TYPE __sync_val_compare_and_swap (TYPE *ptr, TYPE oldval TYPE newval, ...)
__sync_synchronize (...)
TYPE __sync_lock_test_and_set (TYPE *ptr, TYPE value, ...)
void __sync_lock_release (TYPE *ptr, ...)
They're apparently taken from the Intel Itanium reference manual, but GCC implements them on any CPU they can be (and warns if you use one on a CPU that doesn't, then uses a non-atomic version). The function you noted is actually an extended memory barrier (or critical area): the barrier is established by __sync_lock_test_and_set, and released by __sync_lock_release.
If you're looking for a basic atomic fetch-and-set, it's probably __sync_val_compare_and_swap although in most cases you'll want to use one of the more specific versions.

Resources