repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
tsuna/gohbase
region/multi.go
ToProto
func (m *multi) ToProto() proto.Message { // aggregate calls per region actionsPerReg := map[hrpc.RegionInfo][]*pb.Action{} for i, c := range m.calls { select { case <-c.Context().Done(): // context has expired, don't bother sending it m.calls[i] = nil continue default: } msg := c.ToProto() a := &pb.Action{ Index: proto.Uint32(uint32(i) + 1), // +1 because 0 index means there's no index } switch r := msg.(type) { case *pb.GetRequest: a.Get = r.Get case *pb.MutateRequest: a.Mutation = r.Mutation default: panic(fmt.Sprintf("unsupported call type for Multi: %T", c)) } actionsPerReg[c.Region()] = append(actionsPerReg[c.Region()], a) } // construct the multi proto ra := make([]*pb.RegionAction, len(actionsPerReg)) m.regions = make([]hrpc.RegionInfo, len(actionsPerReg)) i := 0 for r, as := range actionsPerReg { ra[i] = &pb.RegionAction{ Region: &pb.RegionSpecifier{ Type: pb.RegionSpecifier_REGION_NAME.Enum(), Value: r.Name(), }, Action: as, } // Track the order of RegionActions, // so that we can handle whole region exceptions. m.regions[i] = r i++ } return &pb.MultiRequest{RegionAction: ra} }
go
func (m *multi) ToProto() proto.Message { // aggregate calls per region actionsPerReg := map[hrpc.RegionInfo][]*pb.Action{} for i, c := range m.calls { select { case <-c.Context().Done(): // context has expired, don't bother sending it m.calls[i] = nil continue default: } msg := c.ToProto() a := &pb.Action{ Index: proto.Uint32(uint32(i) + 1), // +1 because 0 index means there's no index } switch r := msg.(type) { case *pb.GetRequest: a.Get = r.Get case *pb.MutateRequest: a.Mutation = r.Mutation default: panic(fmt.Sprintf("unsupported call type for Multi: %T", c)) } actionsPerReg[c.Region()] = append(actionsPerReg[c.Region()], a) } // construct the multi proto ra := make([]*pb.RegionAction, len(actionsPerReg)) m.regions = make([]hrpc.RegionInfo, len(actionsPerReg)) i := 0 for r, as := range actionsPerReg { ra[i] = &pb.RegionAction{ Region: &pb.RegionSpecifier{ Type: pb.RegionSpecifier_REGION_NAME.Enum(), Value: r.Name(), }, Action: as, } // Track the order of RegionActions, // so that we can handle whole region exceptions. m.regions[i] = r i++ } return &pb.MultiRequest{RegionAction: ra} }
[ "func", "(", "m", "*", "multi", ")", "ToProto", "(", ")", "proto", ".", "Message", "{", "// aggregate calls per region", "actionsPerReg", ":=", "map", "[", "hrpc", ".", "RegionInfo", "]", "[", "]", "*", "pb", ".", "Action", "{", "}", "\n\n", "for", "i"...
// ToProto converts all request in multi batch to a protobuf message.
[ "ToProto", "converts", "all", "request", "in", "multi", "batch", "to", "a", "protobuf", "message", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/region/multi.go#L51-L101
train
tsuna/gohbase
region/multi.go
DeserializeCellBlocks
func (m *multi) DeserializeCellBlocks(msg proto.Message, b []byte) (uint32, error) { mr := msg.(*pb.MultiResponse) var nread uint32 for _, rar := range mr.GetRegionActionResult() { if e := rar.GetException(); e != nil { if l := len(rar.GetResultOrException()); l != 0 { return 0, fmt.Errorf( "got exception for region, but still have %d result(s) returned from it", l) } continue } for _, roe := range rar.GetResultOrException() { e := roe.GetException() r := roe.GetResult() i := roe.GetIndex() if i == 0 { return 0, errors.New("no index for result in multi response") } else if r == nil && e == nil { return 0, errors.New("no result or exception for action in multi response") } else if r != nil && e != nil { return 0, errors.New("got result and exception for action in multi response") } else if e != nil { continue } c := m.get(i) // TODO: maybe return error if it's out-of-bounds d := c.(canDeserializeCellBlocks) // let it panic, because then it's our bug response := c.NewResponse() switch rsp := response.(type) { case *pb.GetResponse: rsp.Result = r case *pb.MutateResponse: rsp.Result = r default: panic(fmt.Sprintf("unsupported response type for Multi: %T", response)) } // TODO: don't bother deserializing if the call's context has already expired n, err := d.DeserializeCellBlocks(response, b[nread:]) if err != nil { return 0, fmt.Errorf( "error deserializing cellblocks for %q call as part of MultiResponse: %v", c.Name(), err) } nread += n } } return nread, nil }
go
func (m *multi) DeserializeCellBlocks(msg proto.Message, b []byte) (uint32, error) { mr := msg.(*pb.MultiResponse) var nread uint32 for _, rar := range mr.GetRegionActionResult() { if e := rar.GetException(); e != nil { if l := len(rar.GetResultOrException()); l != 0 { return 0, fmt.Errorf( "got exception for region, but still have %d result(s) returned from it", l) } continue } for _, roe := range rar.GetResultOrException() { e := roe.GetException() r := roe.GetResult() i := roe.GetIndex() if i == 0 { return 0, errors.New("no index for result in multi response") } else if r == nil && e == nil { return 0, errors.New("no result or exception for action in multi response") } else if r != nil && e != nil { return 0, errors.New("got result and exception for action in multi response") } else if e != nil { continue } c := m.get(i) // TODO: maybe return error if it's out-of-bounds d := c.(canDeserializeCellBlocks) // let it panic, because then it's our bug response := c.NewResponse() switch rsp := response.(type) { case *pb.GetResponse: rsp.Result = r case *pb.MutateResponse: rsp.Result = r default: panic(fmt.Sprintf("unsupported response type for Multi: %T", response)) } // TODO: don't bother deserializing if the call's context has already expired n, err := d.DeserializeCellBlocks(response, b[nread:]) if err != nil { return 0, fmt.Errorf( "error deserializing cellblocks for %q call as part of MultiResponse: %v", c.Name(), err) } nread += n } } return nread, nil }
[ "func", "(", "m", "*", "multi", ")", "DeserializeCellBlocks", "(", "msg", "proto", ".", "Message", ",", "b", "[", "]", "byte", ")", "(", "uint32", ",", "error", ")", "{", "mr", ":=", "msg", ".", "(", "*", "pb", ".", "MultiResponse", ")", "\n\n", ...
// DeserializeCellBlocks deserializes action results from cell blocks.
[ "DeserializeCellBlocks", "deserializes", "action", "results", "from", "cell", "blocks", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/region/multi.go#L109-L161
train
tsuna/gohbase
region/multi.go
add
func (m *multi) add(call hrpc.Call) bool { m.calls = append(m.calls, call) return len(m.calls) == m.size }
go
func (m *multi) add(call hrpc.Call) bool { m.calls = append(m.calls, call) return len(m.calls) == m.size }
[ "func", "(", "m", "*", "multi", ")", "add", "(", "call", "hrpc", ".", "Call", ")", "bool", "{", "m", ".", "calls", "=", "append", "(", "m", ".", "calls", ",", "call", ")", "\n", "return", "len", "(", "m", ".", "calls", ")", "==", "m", ".", ...
// add adds the call and returns wether the batch is full.
[ "add", "adds", "the", "call", "and", "returns", "wether", "the", "batch", "is", "full", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/region/multi.go#L230-L233
train
tsuna/gohbase
region/multi.go
get
func (m *multi) get(i uint32) hrpc.Call { if i == 0 { panic("index cannot be 0") } return m.calls[i-1] }
go
func (m *multi) get(i uint32) hrpc.Call { if i == 0 { panic("index cannot be 0") } return m.calls[i-1] }
[ "func", "(", "m", "*", "multi", ")", "get", "(", "i", "uint32", ")", "hrpc", ".", "Call", "{", "if", "i", "==", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "m", ".", "calls", "[", "i", "-", "1", "]", "\n", "}" ]
// get retruns an rpc at index. Indicies start from 1 since 0 means that // region server didn't set an index for the action result.
[ "get", "retruns", "an", "rpc", "at", "index", ".", "Indicies", "start", "from", "1", "since", "0", "means", "that", "region", "server", "didn", "t", "set", "an", "index", "for", "the", "action", "result", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/region/multi.go#L242-L247
train
tsuna/gohbase
region/info.go
NewInfo
func NewInfo(id uint64, namespace, table, name, startKey, stopKey []byte) hrpc.RegionInfo { ctx, cancel := context.WithCancel(context.Background()) return &info{ id: id, ctx: ctx, cancel: cancel, namespace: namespace, table: table, name: name, startKey: startKey, stopKey: stopKey, } }
go
func NewInfo(id uint64, namespace, table, name, startKey, stopKey []byte) hrpc.RegionInfo { ctx, cancel := context.WithCancel(context.Background()) return &info{ id: id, ctx: ctx, cancel: cancel, namespace: namespace, table: table, name: name, startKey: startKey, stopKey: stopKey, } }
[ "func", "NewInfo", "(", "id", "uint64", ",", "namespace", ",", "table", ",", "name", ",", "startKey", ",", "stopKey", "[", "]", "byte", ")", "hrpc", ".", "RegionInfo", "{", "ctx", ",", "cancel", ":=", "context", ".", "WithCancel", "(", "context", ".", ...
// NewInfo creates a new region info
[ "NewInfo", "creates", "a", "new", "region", "info" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/region/info.go#L58-L70
train
tsuna/gohbase
region/info.go
infoFromCell
func infoFromCell(cell *hrpc.Cell) (hrpc.RegionInfo, error) { value := cell.Value if len(value) == 0 { return nil, fmt.Errorf("empty value in %q", cell) } else if value[0] != 'P' { return nil, fmt.Errorf("unsupported region info version %d in %q", value[0], cell) } const pbufMagic = 1346524486 // 4 bytes: "PBUF" magic := binary.BigEndian.Uint32(value[:4]) if magic != pbufMagic { return nil, fmt.Errorf("invalid magic number in %q", cell) } var regInfo pb.RegionInfo err := proto.UnmarshalMerge(value[4:], &regInfo) if err != nil { return nil, fmt.Errorf("failed to decode %q: %s", cell, err) } if regInfo.GetOffline() { return nil, OfflineRegionError{n: string(cell.Row)} } var namespace []byte if !bytes.Equal(regInfo.TableName.Namespace, defaultNamespace) { // if default namespace, pretend there's no namespace namespace = regInfo.TableName.Namespace } return NewInfo( regInfo.GetRegionId(), namespace, regInfo.TableName.Qualifier, cell.Row, regInfo.StartKey, regInfo.EndKey, ), nil }
go
func infoFromCell(cell *hrpc.Cell) (hrpc.RegionInfo, error) { value := cell.Value if len(value) == 0 { return nil, fmt.Errorf("empty value in %q", cell) } else if value[0] != 'P' { return nil, fmt.Errorf("unsupported region info version %d in %q", value[0], cell) } const pbufMagic = 1346524486 // 4 bytes: "PBUF" magic := binary.BigEndian.Uint32(value[:4]) if magic != pbufMagic { return nil, fmt.Errorf("invalid magic number in %q", cell) } var regInfo pb.RegionInfo err := proto.UnmarshalMerge(value[4:], &regInfo) if err != nil { return nil, fmt.Errorf("failed to decode %q: %s", cell, err) } if regInfo.GetOffline() { return nil, OfflineRegionError{n: string(cell.Row)} } var namespace []byte if !bytes.Equal(regInfo.TableName.Namespace, defaultNamespace) { // if default namespace, pretend there's no namespace namespace = regInfo.TableName.Namespace } return NewInfo( regInfo.GetRegionId(), namespace, regInfo.TableName.Qualifier, cell.Row, regInfo.StartKey, regInfo.EndKey, ), nil }
[ "func", "infoFromCell", "(", "cell", "*", "hrpc", ".", "Cell", ")", "(", "hrpc", ".", "RegionInfo", ",", "error", ")", "{", "value", ":=", "cell", ".", "Value", "\n", "if", "len", "(", "value", ")", "==", "0", "{", "return", "nil", ",", "fmt", "....
// infoFromCell parses a KeyValue from the meta table and creates the // corresponding Info object.
[ "infoFromCell", "parses", "a", "KeyValue", "from", "the", "meta", "table", "and", "creates", "the", "corresponding", "Info", "object", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/region/info.go#L74-L108
train
tsuna/gohbase
region/info.go
IsUnavailable
func (i *info) IsUnavailable() bool { i.m.RLock() res := i.available != nil i.m.RUnlock() return res }
go
func (i *info) IsUnavailable() bool { i.m.RLock() res := i.available != nil i.m.RUnlock() return res }
[ "func", "(", "i", "*", "info", ")", "IsUnavailable", "(", ")", "bool", "{", "i", ".", "m", ".", "RLock", "(", ")", "\n", "res", ":=", "i", ".", "available", "!=", "nil", "\n", "i", ".", "m", ".", "RUnlock", "(", ")", "\n", "return", "res", "\...
// IsUnavailable returns true if this region has been marked as unavailable.
[ "IsUnavailable", "returns", "true", "if", "this", "region", "has", "been", "marked", "as", "unavailable", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/region/info.go#L150-L155
train
tsuna/gohbase
region/info.go
AvailabilityChan
func (i *info) AvailabilityChan() <-chan struct{} { i.m.RLock() ch := i.available i.m.RUnlock() return ch }
go
func (i *info) AvailabilityChan() <-chan struct{} { i.m.RLock() ch := i.available i.m.RUnlock() return ch }
[ "func", "(", "i", "*", "info", ")", "AvailabilityChan", "(", ")", "<-", "chan", "struct", "{", "}", "{", "i", ".", "m", ".", "RLock", "(", ")", "\n", "ch", ":=", "i", ".", "available", "\n", "i", ".", "m", ".", "RUnlock", "(", ")", "\n", "ret...
// AvailabilityChan returns a channel that can be used to wait on for // notification that a connection to this region has been reestablished. // If this region is not marked as unavailable, nil will be returned.
[ "AvailabilityChan", "returns", "a", "channel", "that", "can", "be", "used", "to", "wait", "on", "for", "notification", "that", "a", "connection", "to", "this", "region", "has", "been", "reestablished", ".", "If", "this", "region", "is", "not", "marked", "as"...
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/region/info.go#L160-L165
train
tsuna/gohbase
region/info.go
MarkUnavailable
func (i *info) MarkUnavailable() bool { created := false i.m.Lock() if i.available == nil { i.available = make(chan struct{}) created = true } i.m.Unlock() return created }
go
func (i *info) MarkUnavailable() bool { created := false i.m.Lock() if i.available == nil { i.available = make(chan struct{}) created = true } i.m.Unlock() return created }
[ "func", "(", "i", "*", "info", ")", "MarkUnavailable", "(", ")", "bool", "{", "created", ":=", "false", "\n", "i", ".", "m", ".", "Lock", "(", ")", "\n", "if", "i", ".", "available", "==", "nil", "{", "i", ".", "available", "=", "make", "(", "c...
// MarkUnavailable will mark this region as unavailable, by creating the struct // returned by AvailabilityChan. If this region was marked as available // before this, true will be returned.
[ "MarkUnavailable", "will", "mark", "this", "region", "as", "unavailable", "by", "creating", "the", "struct", "returned", "by", "AvailabilityChan", ".", "If", "this", "region", "was", "marked", "as", "available", "before", "this", "true", "will", "be", "returned"...
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/region/info.go#L170-L179
train
tsuna/gohbase
region/info.go
MarkAvailable
func (i *info) MarkAvailable() { i.m.Lock() ch := i.available i.available = nil close(ch) i.m.Unlock() }
go
func (i *info) MarkAvailable() { i.m.Lock() ch := i.available i.available = nil close(ch) i.m.Unlock() }
[ "func", "(", "i", "*", "info", ")", "MarkAvailable", "(", ")", "{", "i", ".", "m", ".", "Lock", "(", ")", "\n", "ch", ":=", "i", ".", "available", "\n", "i", ".", "available", "=", "nil", "\n", "close", "(", "ch", ")", "\n", "i", ".", "m", ...
// MarkAvailable will mark this region as available again, by closing the struct // returned by AvailabilityChan
[ "MarkAvailable", "will", "mark", "this", "region", "as", "available", "again", "by", "closing", "the", "struct", "returned", "by", "AvailabilityChan" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/region/info.go#L183-L189
train
tsuna/gohbase
region/info.go
Client
func (i *info) Client() hrpc.RegionClient { i.m.RLock() c := i.client i.m.RUnlock() return c }
go
func (i *info) Client() hrpc.RegionClient { i.m.RLock() c := i.client i.m.RUnlock() return c }
[ "func", "(", "i", "*", "info", ")", "Client", "(", ")", "hrpc", ".", "RegionClient", "{", "i", ".", "m", ".", "RLock", "(", ")", "\n", "c", ":=", "i", ".", "client", "\n", "i", ".", "m", ".", "RUnlock", "(", ")", "\n", "return", "c", "\n", ...
// Client returns region client
[ "Client", "returns", "region", "client" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/region/info.go#L239-L244
train
tsuna/gohbase
region/info.go
SetClient
func (i *info) SetClient(c hrpc.RegionClient) { i.m.Lock() i.client = c i.m.Unlock() }
go
func (i *info) SetClient(c hrpc.RegionClient) { i.m.Lock() i.client = c i.m.Unlock() }
[ "func", "(", "i", "*", "info", ")", "SetClient", "(", "c", "hrpc", ".", "RegionClient", ")", "{", "i", ".", "m", ".", "Lock", "(", ")", "\n", "i", ".", "client", "=", "c", "\n", "i", ".", "m", ".", "Unlock", "(", ")", "\n", "}" ]
// SetClient sets region client
[ "SetClient", "sets", "region", "client" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/region/info.go#L247-L251
train
tsuna/gohbase
hrpc/procedure.go
NewGetProcedureState
func NewGetProcedureState(ctx context.Context, procID uint64) *GetProcedureState { return &GetProcedureState{ base: base{ ctx: ctx, resultch: make(chan RPCResult, 1), }, procID: procID, } }
go
func NewGetProcedureState(ctx context.Context, procID uint64) *GetProcedureState { return &GetProcedureState{ base: base{ ctx: ctx, resultch: make(chan RPCResult, 1), }, procID: procID, } }
[ "func", "NewGetProcedureState", "(", "ctx", "context", ".", "Context", ",", "procID", "uint64", ")", "*", "GetProcedureState", "{", "return", "&", "GetProcedureState", "{", "base", ":", "base", "{", "ctx", ":", "ctx", ",", "resultch", ":", "make", "(", "ch...
// NewGetProcedureState creates a new GetProcedureState request. For use by the admin client.
[ "NewGetProcedureState", "creates", "a", "new", "GetProcedureState", "request", ".", "For", "use", "by", "the", "admin", "client", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/procedure.go#L23-L31
train
tsuna/gohbase
client.go
ZookeeperTimeout
func ZookeeperTimeout(to time.Duration) Option { return func(c *client) { c.zkTimeout = to } }
go
func ZookeeperTimeout(to time.Duration) Option { return func(c *client) { c.zkTimeout = to } }
[ "func", "ZookeeperTimeout", "(", "to", "time", ".", "Duration", ")", "Option", "{", "return", "func", "(", "c", "*", "client", ")", "{", "c", ".", "zkTimeout", "=", "to", "\n", "}", "\n", "}" ]
// ZookeeperTimeout will return an option that will set the zookeeper session timeout.
[ "ZookeeperTimeout", "will", "return", "an", "option", "that", "will", "set", "the", "zookeeper", "session", "timeout", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/client.go#L165-L169
train
tsuna/gohbase
client.go
RegionLookupTimeout
func RegionLookupTimeout(to time.Duration) Option { return func(c *client) { c.regionLookupTimeout = to } }
go
func RegionLookupTimeout(to time.Duration) Option { return func(c *client) { c.regionLookupTimeout = to } }
[ "func", "RegionLookupTimeout", "(", "to", "time", ".", "Duration", ")", "Option", "{", "return", "func", "(", "c", "*", "client", ")", "{", "c", ".", "regionLookupTimeout", "=", "to", "\n", "}", "\n", "}" ]
// RegionLookupTimeout will return an option that sets the region lookup timeout
[ "RegionLookupTimeout", "will", "return", "an", "option", "that", "sets", "the", "region", "lookup", "timeout" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/client.go#L172-L176
train
tsuna/gohbase
client.go
RegionReadTimeout
func RegionReadTimeout(to time.Duration) Option { return func(c *client) { c.regionReadTimeout = to } }
go
func RegionReadTimeout(to time.Duration) Option { return func(c *client) { c.regionReadTimeout = to } }
[ "func", "RegionReadTimeout", "(", "to", "time", ".", "Duration", ")", "Option", "{", "return", "func", "(", "c", "*", "client", ")", "{", "c", ".", "regionReadTimeout", "=", "to", "\n", "}", "\n", "}" ]
// RegionReadTimeout will return an option that sets the region read timeout
[ "RegionReadTimeout", "will", "return", "an", "option", "that", "sets", "the", "region", "read", "timeout" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/client.go#L179-L183
train
tsuna/gohbase
client.go
FlushInterval
func FlushInterval(interval time.Duration) Option { return func(c *client) { c.flushInterval = interval } }
go
func FlushInterval(interval time.Duration) Option { return func(c *client) { c.flushInterval = interval } }
[ "func", "FlushInterval", "(", "interval", "time", ".", "Duration", ")", "Option", "{", "return", "func", "(", "c", "*", "client", ")", "{", "c", ".", "flushInterval", "=", "interval", "\n", "}", "\n", "}" ]
// FlushInterval will return an option that will set the timeout for flushing // the RPC queues used in a given client
[ "FlushInterval", "will", "return", "an", "option", "that", "will", "set", "the", "timeout", "for", "flushing", "the", "RPC", "queues", "used", "in", "a", "given", "client" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/client.go#L194-L198
train
tsuna/gohbase
client.go
Close
func (c *client) Close() { c.closeOnce.Do(func() { close(c.done) if c.clientType == adminClient { if ac := c.adminRegionInfo.Client(); ac != nil { ac.Close() } } c.clients.closeAll() }) }
go
func (c *client) Close() { c.closeOnce.Do(func() { close(c.done) if c.clientType == adminClient { if ac := c.adminRegionInfo.Client(); ac != nil { ac.Close() } } c.clients.closeAll() }) }
[ "func", "(", "c", "*", "client", ")", "Close", "(", ")", "{", "c", ".", "closeOnce", ".", "Do", "(", "func", "(", ")", "{", "close", "(", "c", ".", "done", ")", "\n", "if", "c", ".", "clientType", "==", "adminClient", "{", "if", "ac", ":=", "...
// Close closes connections to hbase master and regionservers
[ "Close", "closes", "connections", "to", "hbase", "master", "and", "regionservers" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/client.go#L201-L211
train
tsuna/gohbase
hrpc/disable.go
NewDisableTable
func NewDisableTable(ctx context.Context, table []byte) *DisableTable { return &DisableTable{ base{ table: table, ctx: ctx, resultch: make(chan RPCResult, 1), }, } }
go
func NewDisableTable(ctx context.Context, table []byte) *DisableTable { return &DisableTable{ base{ table: table, ctx: ctx, resultch: make(chan RPCResult, 1), }, } }
[ "func", "NewDisableTable", "(", "ctx", "context", ".", "Context", ",", "table", "[", "]", "byte", ")", "*", "DisableTable", "{", "return", "&", "DisableTable", "{", "base", "{", "table", ":", "table", ",", "ctx", ":", "ctx", ",", "resultch", ":", "make...
// NewDisableTable creates a new DisableTable request that will disable the // given table in HBase. For use by the admin client.
[ "NewDisableTable", "creates", "a", "new", "DisableTable", "request", "that", "will", "disable", "the", "given", "table", "in", "HBase", ".", "For", "use", "by", "the", "admin", "client", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/disable.go#L22-L30
train
tsuna/gohbase
hrpc/create.go
NewCreateTable
func NewCreateTable(ctx context.Context, table []byte, families map[string]map[string]string, options ...func(*CreateTable)) *CreateTable { ct := &CreateTable{ base: base{ table: table, ctx: ctx, resultch: make(chan RPCResult, 1), }, families: make(map[string]map[string]string, len(families)), } for _, option := range options { option(ct) } for family, attrs := range families { ct.families[family] = make(map[string]string, len(defaultAttributes)) for k, dv := range defaultAttributes { if v, ok := attrs[k]; ok { ct.families[family][k] = v } else { ct.families[family][k] = dv } } } return ct }
go
func NewCreateTable(ctx context.Context, table []byte, families map[string]map[string]string, options ...func(*CreateTable)) *CreateTable { ct := &CreateTable{ base: base{ table: table, ctx: ctx, resultch: make(chan RPCResult, 1), }, families: make(map[string]map[string]string, len(families)), } for _, option := range options { option(ct) } for family, attrs := range families { ct.families[family] = make(map[string]string, len(defaultAttributes)) for k, dv := range defaultAttributes { if v, ok := attrs[k]; ok { ct.families[family][k] = v } else { ct.families[family][k] = dv } } } return ct }
[ "func", "NewCreateTable", "(", "ctx", "context", ".", "Context", ",", "table", "[", "]", "byte", ",", "families", "map", "[", "string", "]", "map", "[", "string", "]", "string", ",", "options", "...", "func", "(", "*", "CreateTable", ")", ")", "*", "...
// NewCreateTable creates a new CreateTable request that will create the given // table in HBase. 'families' is a map of column family name to its attributes. // For use by the admin client.
[ "NewCreateTable", "creates", "a", "new", "CreateTable", "request", "that", "will", "create", "the", "given", "table", "in", "HBase", ".", "families", "is", "a", "map", "of", "column", "family", "name", "to", "its", "attributes", ".", "For", "use", "by", "t...
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/create.go#L40-L65
train
tsuna/gohbase
hrpc/delete.go
NewDeleteTable
func NewDeleteTable(ctx context.Context, table []byte) *DeleteTable { return &DeleteTable{ base{ table: table, ctx: ctx, resultch: make(chan RPCResult, 1), }, } }
go
func NewDeleteTable(ctx context.Context, table []byte) *DeleteTable { return &DeleteTable{ base{ table: table, ctx: ctx, resultch: make(chan RPCResult, 1), }, } }
[ "func", "NewDeleteTable", "(", "ctx", "context", ".", "Context", ",", "table", "[", "]", "byte", ")", "*", "DeleteTable", "{", "return", "&", "DeleteTable", "{", "base", "{", "table", ":", "table", ",", "ctx", ":", "ctx", ",", "resultch", ":", "make", ...
// NewDeleteTable creates a new DeleteTable request that will delete the // given table in HBase. For use by the admin client.
[ "NewDeleteTable", "creates", "a", "new", "DeleteTable", "request", "that", "will", "delete", "the", "given", "table", "in", "HBase", ".", "For", "use", "by", "the", "admin", "client", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/delete.go#L22-L30
train
tsuna/gohbase
hrpc/call.go
cellFromCellBlock
func cellFromCellBlock(b []byte) (*pb.Cell, uint32, error) { if len(b) < 4 { return nil, 0, fmt.Errorf( "buffer is too small: expected %d, got %d", 4, len(b)) } kvLen := binary.BigEndian.Uint32(b[0:4]) if len(b) < int(kvLen)+4 { return nil, 0, fmt.Errorf( "buffer is too small: expected %d, got %d", int(kvLen)+4, len(b)) } rowKeyLen := binary.BigEndian.Uint32(b[4:8]) valueLen := binary.BigEndian.Uint32(b[8:12]) keyLen := binary.BigEndian.Uint16(b[12:14]) b = b[14:] key := b[:keyLen] b = b[keyLen:] familyLen := uint8(b[0]) b = b[1:] family := b[:familyLen] b = b[familyLen:] qualifierLen := rowKeyLen - uint32(keyLen) - uint32(familyLen) - 2 - 1 - 8 - 1 if 4 /*rowKeyLen*/ +4 /*valueLen*/ +2 /*keyLen*/ + uint32(keyLen)+1 /*familyLen*/ +uint32(familyLen)+qualifierLen+ 8 /*timestamp*/ +1 /*cellType*/ +valueLen != kvLen { return nil, 0, fmt.Errorf("HBase has lied about KeyValue length: expected %d, got %d", kvLen, 4+4+2+uint32(keyLen)+1+uint32(familyLen)+qualifierLen+8+1+valueLen) } qualifier := b[:qualifierLen] b = b[qualifierLen:] timestamp := binary.BigEndian.Uint64(b[:8]) b = b[8:] cellType := uint8(b[0]) b = b[1:] value := b[:valueLen] return &pb.Cell{ Row: key, Family: family, Qualifier: qualifier, Timestamp: &timestamp, Value: value, CellType: pb.CellType(cellType).Enum(), }, kvLen + 4, nil }
go
func cellFromCellBlock(b []byte) (*pb.Cell, uint32, error) { if len(b) < 4 { return nil, 0, fmt.Errorf( "buffer is too small: expected %d, got %d", 4, len(b)) } kvLen := binary.BigEndian.Uint32(b[0:4]) if len(b) < int(kvLen)+4 { return nil, 0, fmt.Errorf( "buffer is too small: expected %d, got %d", int(kvLen)+4, len(b)) } rowKeyLen := binary.BigEndian.Uint32(b[4:8]) valueLen := binary.BigEndian.Uint32(b[8:12]) keyLen := binary.BigEndian.Uint16(b[12:14]) b = b[14:] key := b[:keyLen] b = b[keyLen:] familyLen := uint8(b[0]) b = b[1:] family := b[:familyLen] b = b[familyLen:] qualifierLen := rowKeyLen - uint32(keyLen) - uint32(familyLen) - 2 - 1 - 8 - 1 if 4 /*rowKeyLen*/ +4 /*valueLen*/ +2 /*keyLen*/ + uint32(keyLen)+1 /*familyLen*/ +uint32(familyLen)+qualifierLen+ 8 /*timestamp*/ +1 /*cellType*/ +valueLen != kvLen { return nil, 0, fmt.Errorf("HBase has lied about KeyValue length: expected %d, got %d", kvLen, 4+4+2+uint32(keyLen)+1+uint32(familyLen)+qualifierLen+8+1+valueLen) } qualifier := b[:qualifierLen] b = b[qualifierLen:] timestamp := binary.BigEndian.Uint64(b[:8]) b = b[8:] cellType := uint8(b[0]) b = b[1:] value := b[:valueLen] return &pb.Cell{ Row: key, Family: family, Qualifier: qualifier, Timestamp: &timestamp, Value: value, CellType: pb.CellType(cellType).Enum(), }, kvLen + 4, nil }
[ "func", "cellFromCellBlock", "(", "b", "[", "]", "byte", ")", "(", "*", "pb", ".", "Cell", ",", "uint32", ",", "error", ")", "{", "if", "len", "(", "b", ")", "<", "4", "{", "return", "nil", ",", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\""...
// cellFromCellBlock deserializes a cell from a reader
[ "cellFromCellBlock", "deserializes", "a", "cell", "from", "a", "reader" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/call.go#L176-L228
train
tsuna/gohbase
hrpc/call.go
ToLocalResult
func ToLocalResult(pbr *pb.Result) *Result { if pbr == nil { return &Result{} } return &Result{ // Should all be O(1) operations. Cells: toLocalCells(pbr), Stale: extractBool(pbr.Stale), Partial: extractBool(pbr.Partial), Exists: pbr.Exists, } }
go
func ToLocalResult(pbr *pb.Result) *Result { if pbr == nil { return &Result{} } return &Result{ // Should all be O(1) operations. Cells: toLocalCells(pbr), Stale: extractBool(pbr.Stale), Partial: extractBool(pbr.Partial), Exists: pbr.Exists, } }
[ "func", "ToLocalResult", "(", "pbr", "*", "pb", ".", "Result", ")", "*", "Result", "{", "if", "pbr", "==", "nil", "{", "return", "&", "Result", "{", "}", "\n", "}", "\n", "return", "&", "Result", "{", "// Should all be O(1) operations.", "Cells", ":", ...
// ToLocalResult takes a protobuf Result type and converts it to our own // Result type in constant time.
[ "ToLocalResult", "takes", "a", "protobuf", "Result", "type", "and", "converts", "it", "to", "our", "own", "Result", "type", "in", "constant", "time", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/call.go#L259-L270
train
tsuna/gohbase
caches.go
put
func (krc *keyRegionCache) put(reg hrpc.RegionInfo) (overlaps []hrpc.RegionInfo, replaced bool) { krc.m.Lock() krc.regions.Put(reg.Name(), func(v interface{}, exists bool) (interface{}, bool) { if exists { // region is already in cache, // note: regions with the same name have the same age overlaps = []hrpc.RegionInfo{v.(hrpc.RegionInfo)} return nil, false } // find all entries that are overlapping with the range of the new region. overlaps = krc.getOverlaps(reg) for _, o := range overlaps { if o.ID() > reg.ID() { // overlapping region is younger, // don't replace any regions // TODO: figure out if there can a case where we might // have both older and younger overlapping regions, for // now we only replace if all overlaps are older return nil, false } } // all overlaps are older, put the new region replaced = true return reg, true }) if !replaced { krc.m.Unlock() log.WithFields(log.Fields{ "region": reg, "overlaps": overlaps, "replaced": replaced, }).Debug("region is already in cache") return } // delete overlapping regions // TODO: in case overlaps are always either younger or older, // we can just greedily remove them in Put function for _, o := range overlaps { krc.regions.Delete(o.Name()) // let region establishers know that they can give up o.MarkDead() } krc.m.Unlock() log.WithFields(log.Fields{ "region": reg, "overlaps": overlaps, "replaced": replaced, }).Info("added new region") return }
go
func (krc *keyRegionCache) put(reg hrpc.RegionInfo) (overlaps []hrpc.RegionInfo, replaced bool) { krc.m.Lock() krc.regions.Put(reg.Name(), func(v interface{}, exists bool) (interface{}, bool) { if exists { // region is already in cache, // note: regions with the same name have the same age overlaps = []hrpc.RegionInfo{v.(hrpc.RegionInfo)} return nil, false } // find all entries that are overlapping with the range of the new region. overlaps = krc.getOverlaps(reg) for _, o := range overlaps { if o.ID() > reg.ID() { // overlapping region is younger, // don't replace any regions // TODO: figure out if there can a case where we might // have both older and younger overlapping regions, for // now we only replace if all overlaps are older return nil, false } } // all overlaps are older, put the new region replaced = true return reg, true }) if !replaced { krc.m.Unlock() log.WithFields(log.Fields{ "region": reg, "overlaps": overlaps, "replaced": replaced, }).Debug("region is already in cache") return } // delete overlapping regions // TODO: in case overlaps are always either younger or older, // we can just greedily remove them in Put function for _, o := range overlaps { krc.regions.Delete(o.Name()) // let region establishers know that they can give up o.MarkDead() } krc.m.Unlock() log.WithFields(log.Fields{ "region": reg, "overlaps": overlaps, "replaced": replaced, }).Info("added new region") return }
[ "func", "(", "krc", "*", "keyRegionCache", ")", "put", "(", "reg", "hrpc", ".", "RegionInfo", ")", "(", "overlaps", "[", "]", "hrpc", ".", "RegionInfo", ",", "replaced", "bool", ")", "{", "krc", ".", "m", ".", "Lock", "(", ")", "\n", "krc", ".", ...
// put looks up if there's already region with this name in regions cache // and if there's, returns it in overlaps and doesn't modify the cache. // Otherwise, it puts the region and removes all overlaps in case all of // them are older. Returns a slice of overlapping regions and whether // passed region was put in the cache.
[ "put", "looks", "up", "if", "there", "s", "already", "region", "with", "this", "name", "in", "regions", "cache", "and", "if", "there", "s", "returns", "it", "in", "overlaps", "and", "doesn", "t", "modify", "the", "cache", ".", "Otherwise", "it", "puts", ...
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/caches.go#L211-L262
train
tsuna/gohbase
scanner.go
coalesce
func (s *scanner) coalesce(result, partial *pb.Result) (*pb.Result, bool) { if result == nil { return partial, true } if !result.GetPartial() { // results is not partial, shouldn't coalesce return result, false } if len(partial.Cell) > 0 && !bytes.Equal(result.Cell[0].Row, partial.Cell[0].Row) { // new row result.Partial = proto.Bool(false) return result, false } // same row, add the partial result.Cell = append(result.Cell, partial.Cell...) if partial.GetStale() { result.Stale = proto.Bool(partial.GetStale()) } return result, true }
go
func (s *scanner) coalesce(result, partial *pb.Result) (*pb.Result, bool) { if result == nil { return partial, true } if !result.GetPartial() { // results is not partial, shouldn't coalesce return result, false } if len(partial.Cell) > 0 && !bytes.Equal(result.Cell[0].Row, partial.Cell[0].Row) { // new row result.Partial = proto.Bool(false) return result, false } // same row, add the partial result.Cell = append(result.Cell, partial.Cell...) if partial.GetStale() { result.Stale = proto.Bool(partial.GetStale()) } return result, true }
[ "func", "(", "s", "*", "scanner", ")", "coalesce", "(", "result", ",", "partial", "*", "pb", ".", "Result", ")", "(", "*", "pb", ".", "Result", ",", "bool", ")", "{", "if", "result", "==", "nil", "{", "return", "partial", ",", "true", "\n", "}", ...
// coalesce combines result with partial if they belong to the same row // and returns the coalesced result and whether coalescing happened
[ "coalesce", "combines", "result", "with", "partial", "if", "they", "belong", "to", "the", "same", "row", "and", "returns", "the", "coalesced", "result", "and", "whether", "coalescing", "happened" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/scanner.go#L118-L139
train
tsuna/gohbase
scanner.go
update
func (s *scanner) update(resp *pb.ScanResponse, region hrpc.RegionInfo) { if resp.GetMoreResultsInRegion() { if resp.ScannerId != nil { s.scannerID = resp.GetScannerId() } } else { // we are done with this region, prepare scan for next region s.scannerID = noScannerID // Normal Scan if !s.rpc.Reversed() { s.startRow = region.StopKey() return } // Reversed Scan // return if we are at the end if len(region.StartKey()) == 0 { s.startRow = region.StartKey() return } // create the nearest value lower than the current region startKey rsk := region.StartKey() // if last element is 0x0, just shorten the slice if rsk[len(rsk)-1] == 0x0 { s.startRow = rsk[:len(rsk)-1] return } // otherwise lower the last element byte value by 1 and pad with 0xffs tmp := make([]byte, len(rsk), len(rsk)+len(rowPadding)) copy(tmp, rsk) tmp[len(tmp)-1] = tmp[len(tmp)-1] - 1 s.startRow = append(tmp, rowPadding...) } }
go
func (s *scanner) update(resp *pb.ScanResponse, region hrpc.RegionInfo) { if resp.GetMoreResultsInRegion() { if resp.ScannerId != nil { s.scannerID = resp.GetScannerId() } } else { // we are done with this region, prepare scan for next region s.scannerID = noScannerID // Normal Scan if !s.rpc.Reversed() { s.startRow = region.StopKey() return } // Reversed Scan // return if we are at the end if len(region.StartKey()) == 0 { s.startRow = region.StartKey() return } // create the nearest value lower than the current region startKey rsk := region.StartKey() // if last element is 0x0, just shorten the slice if rsk[len(rsk)-1] == 0x0 { s.startRow = rsk[:len(rsk)-1] return } // otherwise lower the last element byte value by 1 and pad with 0xffs tmp := make([]byte, len(rsk), len(rsk)+len(rowPadding)) copy(tmp, rsk) tmp[len(tmp)-1] = tmp[len(tmp)-1] - 1 s.startRow = append(tmp, rowPadding...) } }
[ "func", "(", "s", "*", "scanner", ")", "update", "(", "resp", "*", "pb", ".", "ScanResponse", ",", "region", "hrpc", ".", "RegionInfo", ")", "{", "if", "resp", ".", "GetMoreResultsInRegion", "(", ")", "{", "if", "resp", ".", "ScannerId", "!=", "nil", ...
// update updates the scanner for the next scan request
[ "update", "updates", "the", "scanner", "for", "the", "next", "scan", "request" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/scanner.go#L243-L279
train
tsuna/gohbase
scanner.go
shouldClose
func (s *scanner) shouldClose(resp *pb.ScanResponse, region hrpc.RegionInfo) bool { if resp.MoreResults != nil && !*resp.MoreResults { // the filter for the whole scan has been exhausted, close the scanner return true } if s.scannerID != noScannerID { // not done with this region yet return false } // Check to see if this region is the last we should scan because: // (1) it's the last region if len(region.StopKey()) == 0 && !s.rpc.Reversed() { return true } if s.rpc.Reversed() && len(region.StartKey()) == 0 { return true } // (3) because its stop_key is greater than or equal to the stop_key of this scanner, // provided that (2) we're not trying to scan until the end of the table. if !s.rpc.Reversed() { return len(s.rpc.StopRow()) != 0 && // (2) bytes.Compare(s.rpc.StopRow(), region.StopKey()) <= 0 // (3) } // Reversed Scanner return len(s.rpc.StopRow()) != 0 && // (2) bytes.Compare(s.rpc.StopRow(), region.StartKey()) >= 0 // (3) }
go
func (s *scanner) shouldClose(resp *pb.ScanResponse, region hrpc.RegionInfo) bool { if resp.MoreResults != nil && !*resp.MoreResults { // the filter for the whole scan has been exhausted, close the scanner return true } if s.scannerID != noScannerID { // not done with this region yet return false } // Check to see if this region is the last we should scan because: // (1) it's the last region if len(region.StopKey()) == 0 && !s.rpc.Reversed() { return true } if s.rpc.Reversed() && len(region.StartKey()) == 0 { return true } // (3) because its stop_key is greater than or equal to the stop_key of this scanner, // provided that (2) we're not trying to scan until the end of the table. if !s.rpc.Reversed() { return len(s.rpc.StopRow()) != 0 && // (2) bytes.Compare(s.rpc.StopRow(), region.StopKey()) <= 0 // (3) } // Reversed Scanner return len(s.rpc.StopRow()) != 0 && // (2) bytes.Compare(s.rpc.StopRow(), region.StartKey()) >= 0 // (3) }
[ "func", "(", "s", "*", "scanner", ")", "shouldClose", "(", "resp", "*", "pb", ".", "ScanResponse", ",", "region", "hrpc", ".", "RegionInfo", ")", "bool", "{", "if", "resp", ".", "MoreResults", "!=", "nil", "&&", "!", "*", "resp", ".", "MoreResults", ...
// shouldClose check if this scanner should be closed and should stop fetching new results
[ "shouldClose", "check", "if", "this", "scanner", "should", "be", "closed", "and", "should", "stop", "fetching", "new", "results" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/scanner.go#L282-L311
train
tsuna/gohbase
rpc.go
clientDown
func (c *client) clientDown(client hrpc.RegionClient) { downregions := c.clients.clientDown(client) for downreg := range downregions { if downreg.MarkUnavailable() { downreg.SetClient(nil) go c.reestablishRegion(downreg) } } }
go
func (c *client) clientDown(client hrpc.RegionClient) { downregions := c.clients.clientDown(client) for downreg := range downregions { if downreg.MarkUnavailable() { downreg.SetClient(nil) go c.reestablishRegion(downreg) } } }
[ "func", "(", "c", "*", "client", ")", "clientDown", "(", "client", "hrpc", ".", "RegionClient", ")", "{", "downregions", ":=", "c", ".", "clients", ".", "clientDown", "(", "client", ")", "\n", "for", "downreg", ":=", "range", "downregions", "{", "if", ...
// clientDown removes client from cache and marks // all the regions sharing this region's // client as unavailable, and start a goroutine // to reconnect for each of them.
[ "clientDown", "removes", "client", "from", "cache", "and", "marks", "all", "the", "regions", "sharing", "this", "region", "s", "client", "as", "unavailable", "and", "start", "a", "goroutine", "to", "reconnect", "for", "each", "of", "them", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/rpc.go#L186-L194
train
tsuna/gohbase
rpc.go
getRegionFromCache
func (c *client) getRegionFromCache(table, key []byte) hrpc.RegionInfo { if c.clientType == adminClient { return c.adminRegionInfo } else if bytes.Equal(table, metaTableName) { return c.metaRegionInfo } regionName := createRegionSearchKey(table, key) _, region := c.regions.get(regionName) if region == nil { return nil } // make sure the returned region is for the same table if !bytes.Equal(fullyQualifiedTable(region), table) { // not the same table, can happen if we got the last region return nil } if len(region.StopKey()) != 0 && // If the stop key is an empty byte array, it means this region is the // last region for this table and this key ought to be in that region. bytes.Compare(key, region.StopKey()) >= 0 { return nil } return region }
go
func (c *client) getRegionFromCache(table, key []byte) hrpc.RegionInfo { if c.clientType == adminClient { return c.adminRegionInfo } else if bytes.Equal(table, metaTableName) { return c.metaRegionInfo } regionName := createRegionSearchKey(table, key) _, region := c.regions.get(regionName) if region == nil { return nil } // make sure the returned region is for the same table if !bytes.Equal(fullyQualifiedTable(region), table) { // not the same table, can happen if we got the last region return nil } if len(region.StopKey()) != 0 && // If the stop key is an empty byte array, it means this region is the // last region for this table and this key ought to be in that region. bytes.Compare(key, region.StopKey()) >= 0 { return nil } return region }
[ "func", "(", "c", "*", "client", ")", "getRegionFromCache", "(", "table", ",", "key", "[", "]", "byte", ")", "hrpc", ".", "RegionInfo", "{", "if", "c", ".", "clientType", "==", "adminClient", "{", "return", "c", ".", "adminRegionInfo", "\n", "}", "else...
// Searches in the regions cache for the region hosting the given row.
[ "Searches", "in", "the", "regions", "cache", "for", "the", "region", "hosting", "the", "given", "row", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/rpc.go#L301-L327
train
tsuna/gohbase
rpc.go
createRegionSearchKey
func createRegionSearchKey(table, key []byte) []byte { metaKey := make([]byte, 0, len(table)+len(key)+3) metaKey = append(metaKey, table...) metaKey = append(metaKey, ',') metaKey = append(metaKey, key...) metaKey = append(metaKey, ',') // ':' is the first byte greater than '9'. We always want to find the // entry with the greatest timestamp, so by looking right before ':' // we'll find it. metaKey = append(metaKey, ':') return metaKey }
go
func createRegionSearchKey(table, key []byte) []byte { metaKey := make([]byte, 0, len(table)+len(key)+3) metaKey = append(metaKey, table...) metaKey = append(metaKey, ',') metaKey = append(metaKey, key...) metaKey = append(metaKey, ',') // ':' is the first byte greater than '9'. We always want to find the // entry with the greatest timestamp, so by looking right before ':' // we'll find it. metaKey = append(metaKey, ':') return metaKey }
[ "func", "createRegionSearchKey", "(", "table", ",", "key", "[", "]", "byte", ")", "[", "]", "byte", "{", "metaKey", ":=", "make", "(", "[", "]", "byte", ",", "0", ",", "len", "(", "table", ")", "+", "len", "(", "key", ")", "+", "3", ")", "\n", ...
// Creates the META key to search for in order to locate the given key.
[ "Creates", "the", "META", "key", "to", "search", "for", "in", "order", "to", "locate", "the", "given", "key", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/rpc.go#L330-L341
train
tsuna/gohbase
rpc.go
metaLookup
func (c *client) metaLookup(ctx context.Context, table, key []byte) (hrpc.RegionInfo, string, error) { metaKey := createRegionSearchKey(table, key) rpc, err := hrpc.NewScanRange(ctx, metaTableName, metaKey, table, hrpc.Families(infoFamily), hrpc.Reversed(), hrpc.CloseScanner(), hrpc.NumberOfRows(1)) if err != nil { return nil, "", err } scanner := c.Scan(rpc) resp, err := scanner.Next() if err == io.EOF { return nil, "", TableNotFound } if err != nil { return nil, "", err } reg, addr, err := region.ParseRegionInfo(resp) if err != nil { return nil, "", err } if !bytes.Equal(table, fullyQualifiedTable(reg)) { // This would indicate a bug in HBase. return nil, "", fmt.Errorf("wtf: meta returned an entry for the wrong table!"+ " Looked up table=%q key=%q got region=%s", table, key, reg) } else if len(reg.StopKey()) != 0 && bytes.Compare(key, reg.StopKey()) >= 0 { // This would indicate a hole in the meta table. return nil, "", fmt.Errorf("wtf: meta returned an entry for the wrong region!"+ " Looked up table=%q key=%q got region=%s", table, key, reg) } return reg, addr, nil }
go
func (c *client) metaLookup(ctx context.Context, table, key []byte) (hrpc.RegionInfo, string, error) { metaKey := createRegionSearchKey(table, key) rpc, err := hrpc.NewScanRange(ctx, metaTableName, metaKey, table, hrpc.Families(infoFamily), hrpc.Reversed(), hrpc.CloseScanner(), hrpc.NumberOfRows(1)) if err != nil { return nil, "", err } scanner := c.Scan(rpc) resp, err := scanner.Next() if err == io.EOF { return nil, "", TableNotFound } if err != nil { return nil, "", err } reg, addr, err := region.ParseRegionInfo(resp) if err != nil { return nil, "", err } if !bytes.Equal(table, fullyQualifiedTable(reg)) { // This would indicate a bug in HBase. return nil, "", fmt.Errorf("wtf: meta returned an entry for the wrong table!"+ " Looked up table=%q key=%q got region=%s", table, key, reg) } else if len(reg.StopKey()) != 0 && bytes.Compare(key, reg.StopKey()) >= 0 { // This would indicate a hole in the meta table. return nil, "", fmt.Errorf("wtf: meta returned an entry for the wrong region!"+ " Looked up table=%q key=%q got region=%s", table, key, reg) } return reg, addr, nil }
[ "func", "(", "c", "*", "client", ")", "metaLookup", "(", "ctx", "context", ".", "Context", ",", "table", ",", "key", "[", "]", "byte", ")", "(", "hrpc", ".", "RegionInfo", ",", "string", ",", "error", ")", "{", "metaKey", ":=", "createRegionSearchKey",...
// metaLookup checks meta table for the region in which the given row key for the given table is.
[ "metaLookup", "checks", "meta", "table", "for", "the", "region", "in", "which", "the", "given", "row", "key", "for", "the", "given", "table", "is", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/rpc.go#L370-L406
train
tsuna/gohbase
rpc.go
probeKey
func probeKey(reg hrpc.RegionInfo) []byte { // now we create a probe key: reg.StartKey() + 17 zeros probe := make([]byte, len(reg.StartKey())+17) copy(probe, reg.StartKey()) return probe }
go
func probeKey(reg hrpc.RegionInfo) []byte { // now we create a probe key: reg.StartKey() + 17 zeros probe := make([]byte, len(reg.StartKey())+17) copy(probe, reg.StartKey()) return probe }
[ "func", "probeKey", "(", "reg", "hrpc", ".", "RegionInfo", ")", "[", "]", "byte", "{", "// now we create a probe key: reg.StartKey() + 17 zeros", "probe", ":=", "make", "(", "[", "]", "byte", ",", "len", "(", "reg", ".", "StartKey", "(", ")", ")", "+", "17...
// probeKey returns a key in region that is unlikely to have data at it // in order to test if the region is online. This prevents the Get request // to actually fetch the data from the storage which consumes resources // of the region server
[ "probeKey", "returns", "a", "key", "in", "region", "that", "is", "unlikely", "to", "have", "data", "at", "it", "in", "order", "to", "test", "if", "the", "region", "is", "online", ".", "This", "prevents", "the", "Get", "request", "to", "actually", "fetch"...
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/rpc.go#L437-L442
train
tsuna/gohbase
rpc.go
isRegionEstablished
func isRegionEstablished(rc hrpc.RegionClient, reg hrpc.RegionInfo) error { probe, err := hrpc.NewGet(context.Background(), fullyQualifiedTable(reg), probeKey(reg), hrpc.SkipBatch()) if err != nil { panic(fmt.Sprintf("should not happen: %s", err)) } probe.ExistsOnly() probe.SetRegion(reg) res, err := sendBlocking(rc, probe) if err != nil { panic(fmt.Sprintf("should not happen: %s", err)) } switch res.Error.(type) { case region.ServerError, region.NotServingRegionError, region.RetryableError: return res.Error default: return nil } }
go
func isRegionEstablished(rc hrpc.RegionClient, reg hrpc.RegionInfo) error { probe, err := hrpc.NewGet(context.Background(), fullyQualifiedTable(reg), probeKey(reg), hrpc.SkipBatch()) if err != nil { panic(fmt.Sprintf("should not happen: %s", err)) } probe.ExistsOnly() probe.SetRegion(reg) res, err := sendBlocking(rc, probe) if err != nil { panic(fmt.Sprintf("should not happen: %s", err)) } switch res.Error.(type) { case region.ServerError, region.NotServingRegionError, region.RetryableError: return res.Error default: return nil } }
[ "func", "isRegionEstablished", "(", "rc", "hrpc", ".", "RegionClient", ",", "reg", "hrpc", ".", "RegionInfo", ")", "error", "{", "probe", ",", "err", ":=", "hrpc", ".", "NewGet", "(", "context", ".", "Background", "(", ")", ",", "fullyQualifiedTable", "(",...
// isRegionEstablished checks whether regionserver accepts rpcs for the region. // Returns the cause if not established.
[ "isRegionEstablished", "checks", "whether", "regionserver", "accepts", "rpcs", "for", "the", "region", ".", "Returns", "the", "cause", "if", "not", "established", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/rpc.go#L446-L466
train
tsuna/gohbase
rpc.go
zkLookup
func (c *client) zkLookup(ctx context.Context, resource zk.ResourceName) (string, error) { // We make this a buffered channel so that if we stop waiting due to a // timeout, we won't block the zkLookupSync() that we start in a // separate goroutine. reschan := make(chan zkResult, 1) go func() { addr, err := c.zkClient.LocateResource(resource.Prepend(c.zkRoot)) // This is guaranteed to never block as the channel is always buffered. reschan <- zkResult{addr, err} }() select { case res := <-reschan: return res.addr, res.err case <-ctx.Done(): return "", ctx.Err() } }
go
func (c *client) zkLookup(ctx context.Context, resource zk.ResourceName) (string, error) { // We make this a buffered channel so that if we stop waiting due to a // timeout, we won't block the zkLookupSync() that we start in a // separate goroutine. reschan := make(chan zkResult, 1) go func() { addr, err := c.zkClient.LocateResource(resource.Prepend(c.zkRoot)) // This is guaranteed to never block as the channel is always buffered. reschan <- zkResult{addr, err} }() select { case res := <-reschan: return res.addr, res.err case <-ctx.Done(): return "", ctx.Err() } }
[ "func", "(", "c", "*", "client", ")", "zkLookup", "(", "ctx", "context", ".", "Context", ",", "resource", "zk", ".", "ResourceName", ")", "(", "string", ",", "error", ")", "{", "// We make this a buffered channel so that if we stop waiting due to a", "// timeout, we...
// zkLookup asynchronously looks up the meta region or HMaster in ZooKeeper.
[ "zkLookup", "asynchronously", "looks", "up", "the", "meta", "region", "or", "HMaster", "in", "ZooKeeper", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/rpc.go#L638-L654
train
tsuna/gohbase
hrpc/get.go
baseGet
func baseGet(ctx context.Context, table []byte, key []byte, options ...func(Call) error) (*Get, error) { g := &Get{ base: base{ key: key, table: table, ctx: ctx, resultch: make(chan RPCResult, 1), }, baseQuery: newBaseQuery(), } err := applyOptions(g, options...) if err != nil { return nil, err } return g, nil }
go
func baseGet(ctx context.Context, table []byte, key []byte, options ...func(Call) error) (*Get, error) { g := &Get{ base: base{ key: key, table: table, ctx: ctx, resultch: make(chan RPCResult, 1), }, baseQuery: newBaseQuery(), } err := applyOptions(g, options...) if err != nil { return nil, err } return g, nil }
[ "func", "baseGet", "(", "ctx", "context", ".", "Context", ",", "table", "[", "]", "byte", ",", "key", "[", "]", "byte", ",", "options", "...", "func", "(", "Call", ")", "error", ")", "(", "*", "Get", ",", "error", ")", "{", "g", ":=", "&", "Get...
// baseGet returns a Get struct with default values set.
[ "baseGet", "returns", "a", "Get", "struct", "with", "default", "values", "set", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/get.go#L26-L42
train
tsuna/gohbase
hrpc/get.go
NewGet
func NewGet(ctx context.Context, table, key []byte, options ...func(Call) error) (*Get, error) { return baseGet(ctx, table, key, options...) }
go
func NewGet(ctx context.Context, table, key []byte, options ...func(Call) error) (*Get, error) { return baseGet(ctx, table, key, options...) }
[ "func", "NewGet", "(", "ctx", "context", ".", "Context", ",", "table", ",", "key", "[", "]", "byte", ",", "options", "...", "func", "(", "Call", ")", "error", ")", "(", "*", "Get", ",", "error", ")", "{", "return", "baseGet", "(", "ctx", ",", "ta...
// NewGet creates a new Get request for the given table and row key.
[ "NewGet", "creates", "a", "new", "Get", "request", "for", "the", "given", "table", "and", "row", "key", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/get.go#L45-L48
train
tsuna/gohbase
hrpc/get.go
NewGetStr
func NewGetStr(ctx context.Context, table, key string, options ...func(Call) error) (*Get, error) { return NewGet(ctx, []byte(table), []byte(key), options...) }
go
func NewGetStr(ctx context.Context, table, key string, options ...func(Call) error) (*Get, error) { return NewGet(ctx, []byte(table), []byte(key), options...) }
[ "func", "NewGetStr", "(", "ctx", "context", ".", "Context", ",", "table", ",", "key", "string", ",", "options", "...", "func", "(", "Call", ")", "error", ")", "(", "*", "Get", ",", "error", ")", "{", "return", "NewGet", "(", "ctx", ",", "[", "]", ...
// NewGetStr creates a new Get request for the given table and row key.
[ "NewGetStr", "creates", "a", "new", "Get", "request", "for", "the", "given", "table", "and", "row", "key", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/get.go#L51-L54
train
tsuna/gohbase
hrpc/get.go
ToProto
func (g *Get) ToProto() proto.Message { get := &pb.GetRequest{ Region: g.regionSpecifier(), Get: &pb.Get{ Row: g.key, Column: familiesToColumn(g.families), TimeRange: &pb.TimeRange{}, }, } /* added support for limit number of cells per row */ if g.storeLimit != DefaultMaxResultsPerColumnFamily { get.Get.StoreLimit = &g.storeLimit } if g.storeOffset != 0 { get.Get.StoreOffset = &g.storeOffset } if g.maxVersions != DefaultMaxVersions { get.Get.MaxVersions = &g.maxVersions } if g.fromTimestamp != MinTimestamp { get.Get.TimeRange.From = &g.fromTimestamp } if g.toTimestamp != MaxTimestamp { get.Get.TimeRange.To = &g.toTimestamp } if g.existsOnly { get.Get.ExistenceOnly = proto.Bool(true) } get.Get.Filter = g.filter return get }
go
func (g *Get) ToProto() proto.Message { get := &pb.GetRequest{ Region: g.regionSpecifier(), Get: &pb.Get{ Row: g.key, Column: familiesToColumn(g.families), TimeRange: &pb.TimeRange{}, }, } /* added support for limit number of cells per row */ if g.storeLimit != DefaultMaxResultsPerColumnFamily { get.Get.StoreLimit = &g.storeLimit } if g.storeOffset != 0 { get.Get.StoreOffset = &g.storeOffset } if g.maxVersions != DefaultMaxVersions { get.Get.MaxVersions = &g.maxVersions } if g.fromTimestamp != MinTimestamp { get.Get.TimeRange.From = &g.fromTimestamp } if g.toTimestamp != MaxTimestamp { get.Get.TimeRange.To = &g.toTimestamp } if g.existsOnly { get.Get.ExistenceOnly = proto.Bool(true) } get.Get.Filter = g.filter return get }
[ "func", "(", "g", "*", "Get", ")", "ToProto", "(", ")", "proto", ".", "Message", "{", "get", ":=", "&", "pb", ".", "GetRequest", "{", "Region", ":", "g", ".", "regionSpecifier", "(", ")", ",", "Get", ":", "&", "pb", ".", "Get", "{", "Row", ":",...
// ToProto converts this RPC into a protobuf message.
[ "ToProto", "converts", "this", "RPC", "into", "a", "protobuf", "message", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/get.go#L78-L110
train
tsuna/gohbase
hrpc/get.go
DeserializeCellBlocks
func (g *Get) DeserializeCellBlocks(m proto.Message, b []byte) (uint32, error) { resp := m.(*pb.GetResponse) if resp.Result == nil { // TODO: is this possible? return 0, nil } cells, read, err := deserializeCellBlocks(b, uint32(resp.Result.GetAssociatedCellCount())) if err != nil { return 0, err } resp.Result.Cell = append(resp.Result.Cell, cells...) return read, nil }
go
func (g *Get) DeserializeCellBlocks(m proto.Message, b []byte) (uint32, error) { resp := m.(*pb.GetResponse) if resp.Result == nil { // TODO: is this possible? return 0, nil } cells, read, err := deserializeCellBlocks(b, uint32(resp.Result.GetAssociatedCellCount())) if err != nil { return 0, err } resp.Result.Cell = append(resp.Result.Cell, cells...) return read, nil }
[ "func", "(", "g", "*", "Get", ")", "DeserializeCellBlocks", "(", "m", "proto", ".", "Message", ",", "b", "[", "]", "byte", ")", "(", "uint32", ",", "error", ")", "{", "resp", ":=", "m", ".", "(", "*", "pb", ".", "GetResponse", ")", "\n", "if", ...
// DeserializeCellBlocks deserializes get result from cell blocks
[ "DeserializeCellBlocks", "deserializes", "get", "result", "from", "cell", "blocks" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/get.go#L119-L131
train
tsuna/gohbase
hrpc/get.go
familiesToColumn
func familiesToColumn(families map[string][]string) []*pb.Column { cols := make([]*pb.Column, len(families)) counter := 0 for family, qualifiers := range families { bytequals := make([][]byte, len(qualifiers)) for i, qual := range qualifiers { bytequals[i] = []byte(qual) } cols[counter] = &pb.Column{ Family: []byte(family), Qualifier: bytequals, } counter++ } return cols }
go
func familiesToColumn(families map[string][]string) []*pb.Column { cols := make([]*pb.Column, len(families)) counter := 0 for family, qualifiers := range families { bytequals := make([][]byte, len(qualifiers)) for i, qual := range qualifiers { bytequals[i] = []byte(qual) } cols[counter] = &pb.Column{ Family: []byte(family), Qualifier: bytequals, } counter++ } return cols }
[ "func", "familiesToColumn", "(", "families", "map", "[", "string", "]", "[", "]", "string", ")", "[", "]", "*", "pb", ".", "Column", "{", "cols", ":=", "make", "(", "[", "]", "*", "pb", ".", "Column", ",", "len", "(", "families", ")", ")", "\n", ...
// familiesToColumn takes a map from strings to lists of strings, and converts // them into protobuf Columns
[ "familiesToColumn", "takes", "a", "map", "from", "strings", "to", "lists", "of", "strings", "and", "converts", "them", "into", "protobuf", "Columns" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/get.go#L135-L150
train
tsuna/gohbase
zk/client.go
Prepend
func (r ResourceName) Prepend(prefix string) ResourceName { return ResourceName(path.Join(prefix, string(r))) }
go
func (r ResourceName) Prepend(prefix string) ResourceName { return ResourceName(path.Join(prefix, string(r))) }
[ "func", "(", "r", "ResourceName", ")", "Prepend", "(", "prefix", "string", ")", "ResourceName", "{", "return", "ResourceName", "(", "path", ".", "Join", "(", "prefix", ",", "string", "(", "r", ")", ")", ")", "\n", "}" ]
// Prepend creates a new ResourceName with prefix prepended to the former ResourceName.
[ "Prepend", "creates", "a", "new", "ResourceName", "with", "prefix", "prepended", "to", "the", "former", "ResourceName", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/zk/client.go#L39-L41
train
tsuna/gohbase
zk/client.go
NewClient
func NewClient(zkquorum string, st time.Duration) Client { return &client{ zks: strings.Split(zkquorum, ","), sessionTimeout: st, } }
go
func NewClient(zkquorum string, st time.Duration) Client { return &client{ zks: strings.Split(zkquorum, ","), sessionTimeout: st, } }
[ "func", "NewClient", "(", "zkquorum", "string", ",", "st", "time", ".", "Duration", ")", "Client", "{", "return", "&", "client", "{", "zks", ":", "strings", ".", "Split", "(", "zkquorum", ",", "\"", "\"", ")", ",", "sessionTimeout", ":", "st", ",", "...
// NewClient establishes connection to zookeeper and returns the client
[ "NewClient", "establishes", "connection", "to", "zookeeper", "and", "returns", "the", "client" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/zk/client.go#L64-L69
train
tsuna/gohbase
zk/client.go
LocateResource
func (c *client) LocateResource(resource ResourceName) (string, error) { conn, _, err := zk.Connect(c.zks, c.sessionTimeout) if err != nil { return "", fmt.Errorf("error connecting to ZooKeeper at %v: %s", c.zks, err) } defer conn.Close() buf, _, err := conn.Get(string(resource)) if err != nil { return "", fmt.Errorf("failed to read the %s znode: %s", resource, err) } if len(buf) == 0 { log.Fatalf("%s was empty!", resource) } else if buf[0] != 0xFF { return "", fmt.Errorf("the first byte of %s was 0x%x, not 0xFF", resource, buf[0]) } metadataLen := binary.BigEndian.Uint32(buf[1:]) if metadataLen < 1 || metadataLen > 65000 { return "", fmt.Errorf("invalid metadata length for %s: %d", resource, metadataLen) } buf = buf[1+4+metadataLen:] magic := binary.BigEndian.Uint32(buf) const pbufMagic = 1346524486 // 4 bytes: "PBUF" if magic != pbufMagic { return "", fmt.Errorf("invalid magic number for %s: %d", resource, magic) } buf = buf[4:] var server *pb.ServerName if resource == Meta { meta := &pb.MetaRegionServer{} err = proto.UnmarshalMerge(buf, meta) if err != nil { return "", fmt.Errorf("failed to deserialize the MetaRegionServer entry from ZK: %s", err) } server = meta.Server } else { master := &pb.Master{} err = proto.UnmarshalMerge(buf, master) if err != nil { return "", fmt.Errorf("failed to deserialize the Master entry from ZK: %s", err) } server = master.Master } return net.JoinHostPort(*server.HostName, fmt.Sprint(*server.Port)), nil }
go
func (c *client) LocateResource(resource ResourceName) (string, error) { conn, _, err := zk.Connect(c.zks, c.sessionTimeout) if err != nil { return "", fmt.Errorf("error connecting to ZooKeeper at %v: %s", c.zks, err) } defer conn.Close() buf, _, err := conn.Get(string(resource)) if err != nil { return "", fmt.Errorf("failed to read the %s znode: %s", resource, err) } if len(buf) == 0 { log.Fatalf("%s was empty!", resource) } else if buf[0] != 0xFF { return "", fmt.Errorf("the first byte of %s was 0x%x, not 0xFF", resource, buf[0]) } metadataLen := binary.BigEndian.Uint32(buf[1:]) if metadataLen < 1 || metadataLen > 65000 { return "", fmt.Errorf("invalid metadata length for %s: %d", resource, metadataLen) } buf = buf[1+4+metadataLen:] magic := binary.BigEndian.Uint32(buf) const pbufMagic = 1346524486 // 4 bytes: "PBUF" if magic != pbufMagic { return "", fmt.Errorf("invalid magic number for %s: %d", resource, magic) } buf = buf[4:] var server *pb.ServerName if resource == Meta { meta := &pb.MetaRegionServer{} err = proto.UnmarshalMerge(buf, meta) if err != nil { return "", fmt.Errorf("failed to deserialize the MetaRegionServer entry from ZK: %s", err) } server = meta.Server } else { master := &pb.Master{} err = proto.UnmarshalMerge(buf, master) if err != nil { return "", fmt.Errorf("failed to deserialize the Master entry from ZK: %s", err) } server = master.Master } return net.JoinHostPort(*server.HostName, fmt.Sprint(*server.Port)), nil }
[ "func", "(", "c", "*", "client", ")", "LocateResource", "(", "resource", "ResourceName", ")", "(", "string", ",", "error", ")", "{", "conn", ",", "_", ",", "err", ":=", "zk", ".", "Connect", "(", "c", ".", "zks", ",", "c", ".", "sessionTimeout", ")...
// LocateResource returns address of the server for the specified resource.
[ "LocateResource", "returns", "address", "of", "the", "server", "for", "the", "specified", "resource", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/zk/client.go#L72-L118
train
tsuna/gohbase
hrpc/enable.go
NewEnableTable
func NewEnableTable(ctx context.Context, table []byte) *EnableTable { return &EnableTable{ base{ table: table, ctx: ctx, resultch: make(chan RPCResult, 1), }, } }
go
func NewEnableTable(ctx context.Context, table []byte) *EnableTable { return &EnableTable{ base{ table: table, ctx: ctx, resultch: make(chan RPCResult, 1), }, } }
[ "func", "NewEnableTable", "(", "ctx", "context", ".", "Context", ",", "table", "[", "]", "byte", ")", "*", "EnableTable", "{", "return", "&", "EnableTable", "{", "base", "{", "table", ":", "table", ",", "ctx", ":", "ctx", ",", "resultch", ":", "make", ...
// NewEnableTable creates a new EnableTable request that will enable the // given table in HBase. For use by the admin client.
[ "NewEnableTable", "creates", "a", "new", "EnableTable", "request", "that", "will", "enable", "the", "given", "table", "in", "HBase", ".", "For", "use", "by", "the", "admin", "client", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/enable.go#L22-L30
train
tsuna/gohbase
hrpc/mutate.go
TTL
func TTL(t time.Duration) func(Call) error { return func(o Call) error { m, ok := o.(*Mutate) if !ok { return errors.New("'TTL' option can only be used with mutation queries") } buf := make([]byte, 8) binary.BigEndian.PutUint64(buf, uint64(t.Nanoseconds()/1e6)) m.ttl = buf return nil } }
go
func TTL(t time.Duration) func(Call) error { return func(o Call) error { m, ok := o.(*Mutate) if !ok { return errors.New("'TTL' option can only be used with mutation queries") } buf := make([]byte, 8) binary.BigEndian.PutUint64(buf, uint64(t.Nanoseconds()/1e6)) m.ttl = buf return nil } }
[ "func", "TTL", "(", "t", "time", ".", "Duration", ")", "func", "(", "Call", ")", "error", "{", "return", "func", "(", "o", "Call", ")", "error", "{", "m", ",", "ok", ":=", "o", ".", "(", "*", "Mutate", ")", "\n", "if", "!", "ok", "{", "return...
// TTL sets a time-to-live for mutation queries. // The value will be in millisecond resolution.
[ "TTL", "sets", "a", "time", "-", "to", "-", "live", "for", "mutation", "queries", ".", "The", "value", "will", "be", "in", "millisecond", "resolution", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/mutate.go#L68-L81
train
tsuna/gohbase
hrpc/mutate.go
Timestamp
func Timestamp(ts time.Time) func(Call) error { return func(o Call) error { m, ok := o.(*Mutate) if !ok { return errors.New("'Timestamp' option can only be used with mutation queries") } m.timestamp = uint64(ts.UnixNano() / 1e6) return nil } }
go
func Timestamp(ts time.Time) func(Call) error { return func(o Call) error { m, ok := o.(*Mutate) if !ok { return errors.New("'Timestamp' option can only be used with mutation queries") } m.timestamp = uint64(ts.UnixNano() / 1e6) return nil } }
[ "func", "Timestamp", "(", "ts", "time", ".", "Time", ")", "func", "(", "Call", ")", "error", "{", "return", "func", "(", "o", "Call", ")", "error", "{", "m", ",", "ok", ":=", "o", ".", "(", "*", "Mutate", ")", "\n", "if", "!", "ok", "{", "ret...
// Timestamp sets timestamp for mutation queries. // The time object passed will be rounded to a millisecond resolution, as by default, // if no timestamp is provided, HBase sets it to current time in milliseconds. // In order to have custom time precision, use TimestampUint64 call option for // mutation requests and corresponding TimeRangeUint64 for retrieval requests.
[ "Timestamp", "sets", "timestamp", "for", "mutation", "queries", ".", "The", "time", "object", "passed", "will", "be", "rounded", "to", "a", "millisecond", "resolution", "as", "by", "default", "if", "no", "timestamp", "is", "provided", "HBase", "sets", "it", ...
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/mutate.go#L88-L97
train
tsuna/gohbase
hrpc/mutate.go
TimestampUint64
func TimestampUint64(ts uint64) func(Call) error { return func(o Call) error { m, ok := o.(*Mutate) if !ok { return errors.New("'TimestampUint64' option can only be used with mutation queries") } m.timestamp = ts return nil } }
go
func TimestampUint64(ts uint64) func(Call) error { return func(o Call) error { m, ok := o.(*Mutate) if !ok { return errors.New("'TimestampUint64' option can only be used with mutation queries") } m.timestamp = ts return nil } }
[ "func", "TimestampUint64", "(", "ts", "uint64", ")", "func", "(", "Call", ")", "error", "{", "return", "func", "(", "o", "Call", ")", "error", "{", "m", ",", "ok", ":=", "o", ".", "(", "*", "Mutate", ")", "\n", "if", "!", "ok", "{", "return", "...
// TimestampUint64 sets timestamp for mutation queries.
[ "TimestampUint64", "sets", "timestamp", "for", "mutation", "queries", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/mutate.go#L100-L109
train
tsuna/gohbase
hrpc/mutate.go
Durability
func Durability(d DurabilityType) func(Call) error { return func(o Call) error { m, ok := o.(*Mutate) if !ok { return errors.New("'Durability' option can only be used with mutation queries") } if d < UseDefault || d > FsyncWal { return errors.New("invalid durability value") } m.durability = d return nil } }
go
func Durability(d DurabilityType) func(Call) error { return func(o Call) error { m, ok := o.(*Mutate) if !ok { return errors.New("'Durability' option can only be used with mutation queries") } if d < UseDefault || d > FsyncWal { return errors.New("invalid durability value") } m.durability = d return nil } }
[ "func", "Durability", "(", "d", "DurabilityType", ")", "func", "(", "Call", ")", "error", "{", "return", "func", "(", "o", "Call", ")", "error", "{", "m", ",", "ok", ":=", "o", ".", "(", "*", "Mutate", ")", "\n", "if", "!", "ok", "{", "return", ...
// Durability sets durability for mutation queries.
[ "Durability", "sets", "durability", "for", "mutation", "queries", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/mutate.go#L112-L124
train
tsuna/gohbase
hrpc/mutate.go
baseMutate
func baseMutate(ctx context.Context, table, key []byte, values map[string]map[string][]byte, options ...func(Call) error) (*Mutate, error) { m := &Mutate{ base: base{ table: table, key: key, ctx: ctx, resultch: make(chan RPCResult, 1), }, values: values, timestamp: MaxTimestamp, } err := applyOptions(m, options...) if err != nil { return nil, err } return m, nil }
go
func baseMutate(ctx context.Context, table, key []byte, values map[string]map[string][]byte, options ...func(Call) error) (*Mutate, error) { m := &Mutate{ base: base{ table: table, key: key, ctx: ctx, resultch: make(chan RPCResult, 1), }, values: values, timestamp: MaxTimestamp, } err := applyOptions(m, options...) if err != nil { return nil, err } return m, nil }
[ "func", "baseMutate", "(", "ctx", "context", ".", "Context", ",", "table", ",", "key", "[", "]", "byte", ",", "values", "map", "[", "string", "]", "map", "[", "string", "]", "[", "]", "byte", ",", "options", "...", "func", "(", "Call", ")", "error"...
// baseMutate returns a Mutate struct without the mutationType filled in.
[ "baseMutate", "returns", "a", "Mutate", "struct", "without", "the", "mutationType", "filled", "in", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/mutate.go#L144-L161
train
tsuna/gohbase
hrpc/mutate.go
NewPutStr
func NewPutStr(ctx context.Context, table, key string, values map[string]map[string][]byte, options ...func(Call) error) (*Mutate, error) { return NewPut(ctx, []byte(table), []byte(key), values, options...) }
go
func NewPutStr(ctx context.Context, table, key string, values map[string]map[string][]byte, options ...func(Call) error) (*Mutate, error) { return NewPut(ctx, []byte(table), []byte(key), values, options...) }
[ "func", "NewPutStr", "(", "ctx", "context", ".", "Context", ",", "table", ",", "key", "string", ",", "values", "map", "[", "string", "]", "map", "[", "string", "]", "[", "]", "byte", ",", "options", "...", "func", "(", "Call", ")", "error", ")", "(...
// NewPutStr is just like NewPut but takes table and key as strings.
[ "NewPutStr", "is", "just", "like", "NewPut", "but", "takes", "table", "and", "key", "as", "strings", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/mutate.go#L176-L179
train
tsuna/gohbase
hrpc/mutate.go
NewDelStr
func NewDelStr(ctx context.Context, table, key string, values map[string]map[string][]byte, options ...func(Call) error) (*Mutate, error) { return NewDel(ctx, []byte(table), []byte(key), values, options...) }
go
func NewDelStr(ctx context.Context, table, key string, values map[string]map[string][]byte, options ...func(Call) error) (*Mutate, error) { return NewDel(ctx, []byte(table), []byte(key), values, options...) }
[ "func", "NewDelStr", "(", "ctx", "context", ".", "Context", ",", "table", ",", "key", "string", ",", "values", "map", "[", "string", "]", "map", "[", "string", "]", "[", "]", "byte", ",", "options", "...", "func", "(", "Call", ")", "error", ")", "(...
// NewDelStr is just like NewDel but takes table and key as strings.
[ "NewDelStr", "is", "just", "like", "NewDel", "but", "takes", "table", "and", "key", "as", "strings", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/mutate.go#L223-L226
train
tsuna/gohbase
hrpc/mutate.go
NewAppStr
func NewAppStr(ctx context.Context, table, key string, values map[string]map[string][]byte, options ...func(Call) error) (*Mutate, error) { return NewApp(ctx, []byte(table), []byte(key), values, options...) }
go
func NewAppStr(ctx context.Context, table, key string, values map[string]map[string][]byte, options ...func(Call) error) (*Mutate, error) { return NewApp(ctx, []byte(table), []byte(key), values, options...) }
[ "func", "NewAppStr", "(", "ctx", "context", ".", "Context", ",", "table", ",", "key", "string", ",", "values", "map", "[", "string", "]", "map", "[", "string", "]", "[", "]", "byte", ",", "options", "...", "func", "(", "Call", ")", "error", ")", "(...
// NewAppStr is just like NewApp but takes table and key as strings.
[ "NewAppStr", "is", "just", "like", "NewApp", "but", "takes", "table", "and", "key", "as", "strings", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/mutate.go#L242-L245
train
tsuna/gohbase
hrpc/mutate.go
NewIncSingle
func NewIncSingle(ctx context.Context, table, key []byte, family, qualifier string, amount int64, options ...func(Call) error) (*Mutate, error) { buf := make([]byte, 8) binary.BigEndian.PutUint64(buf, uint64(amount)) value := map[string]map[string][]byte{family: map[string][]byte{qualifier: buf}} return NewInc(ctx, table, key, value, options...) }
go
func NewIncSingle(ctx context.Context, table, key []byte, family, qualifier string, amount int64, options ...func(Call) error) (*Mutate, error) { buf := make([]byte, 8) binary.BigEndian.PutUint64(buf, uint64(amount)) value := map[string]map[string][]byte{family: map[string][]byte{qualifier: buf}} return NewInc(ctx, table, key, value, options...) }
[ "func", "NewIncSingle", "(", "ctx", "context", ".", "Context", ",", "table", ",", "key", "[", "]", "byte", ",", "family", ",", "qualifier", "string", ",", "amount", "int64", ",", "options", "...", "func", "(", "Call", ")", "error", ")", "(", "*", "Mu...
// NewIncSingle creates a new Mutation request that will increment the given value // by amount in HBase under the given table, key, family and qualifier.
[ "NewIncSingle", "creates", "a", "new", "Mutation", "request", "that", "will", "increment", "the", "given", "value", "by", "amount", "in", "HBase", "under", "the", "given", "table", "key", "family", "and", "qualifier", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/mutate.go#L249-L255
train
tsuna/gohbase
hrpc/mutate.go
NewIncStrSingle
func NewIncStrSingle(ctx context.Context, table, key, family, qualifier string, amount int64, options ...func(Call) error) (*Mutate, error) { return NewIncSingle(ctx, []byte(table), []byte(key), family, qualifier, amount, options...) }
go
func NewIncStrSingle(ctx context.Context, table, key, family, qualifier string, amount int64, options ...func(Call) error) (*Mutate, error) { return NewIncSingle(ctx, []byte(table), []byte(key), family, qualifier, amount, options...) }
[ "func", "NewIncStrSingle", "(", "ctx", "context", ".", "Context", ",", "table", ",", "key", ",", "family", ",", "qualifier", "string", ",", "amount", "int64", ",", "options", "...", "func", "(", "Call", ")", "error", ")", "(", "*", "Mutate", ",", "erro...
// NewIncStrSingle is just like NewIncSingle but takes table and key as strings.
[ "NewIncStrSingle", "is", "just", "like", "NewIncSingle", "but", "takes", "table", "and", "key", "as", "strings", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/mutate.go#L258-L261
train
tsuna/gohbase
hrpc/mutate.go
NewInc
func NewInc(ctx context.Context, table, key []byte, values map[string]map[string][]byte, options ...func(Call) error) (*Mutate, error) { m, err := baseMutate(ctx, table, key, values, options...) if err != nil { return nil, err } m.mutationType = pb.MutationProto_INCREMENT return m, nil }
go
func NewInc(ctx context.Context, table, key []byte, values map[string]map[string][]byte, options ...func(Call) error) (*Mutate, error) { m, err := baseMutate(ctx, table, key, values, options...) if err != nil { return nil, err } m.mutationType = pb.MutationProto_INCREMENT return m, nil }
[ "func", "NewInc", "(", "ctx", "context", ".", "Context", ",", "table", ",", "key", "[", "]", "byte", ",", "values", "map", "[", "string", "]", "map", "[", "string", "]", "[", "]", "byte", ",", "options", "...", "func", "(", "Call", ")", "error", ...
// NewInc creates a new Mutation request that will increment the given values // in HBase under the given table and key.
[ "NewInc", "creates", "a", "new", "Mutation", "request", "that", "will", "increment", "the", "given", "values", "in", "HBase", "under", "the", "given", "table", "and", "key", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/mutate.go#L265-L273
train
tsuna/gohbase
hrpc/mutate.go
NewIncStr
func NewIncStr(ctx context.Context, table, key string, values map[string]map[string][]byte, options ...func(Call) error) (*Mutate, error) { return NewInc(ctx, []byte(table), []byte(key), values, options...) }
go
func NewIncStr(ctx context.Context, table, key string, values map[string]map[string][]byte, options ...func(Call) error) (*Mutate, error) { return NewInc(ctx, []byte(table), []byte(key), values, options...) }
[ "func", "NewIncStr", "(", "ctx", "context", ".", "Context", ",", "table", ",", "key", "string", ",", "values", "map", "[", "string", "]", "map", "[", "string", "]", "[", "]", "byte", ",", "options", "...", "func", "(", "Call", ")", "error", ")", "(...
// NewIncStr is just like NewInc but takes table and key as strings.
[ "NewIncStr", "is", "just", "like", "NewInc", "but", "takes", "table", "and", "key", "as", "strings", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/mutate.go#L276-L279
train
tsuna/gohbase
hrpc/mutate.go
DeserializeCellBlocks
func (m *Mutate) DeserializeCellBlocks(pm proto.Message, b []byte) (uint32, error) { resp := pm.(*pb.MutateResponse) if resp.Result == nil { // TODO: is this possible? return 0, nil } cells, read, err := deserializeCellBlocks(b, uint32(resp.Result.GetAssociatedCellCount())) if err != nil { return 0, err } resp.Result.Cell = append(resp.Result.Cell, cells...) return read, nil }
go
func (m *Mutate) DeserializeCellBlocks(pm proto.Message, b []byte) (uint32, error) { resp := pm.(*pb.MutateResponse) if resp.Result == nil { // TODO: is this possible? return 0, nil } cells, read, err := deserializeCellBlocks(b, uint32(resp.Result.GetAssociatedCellCount())) if err != nil { return 0, err } resp.Result.Cell = append(resp.Result.Cell, cells...) return read, nil }
[ "func", "(", "m", "*", "Mutate", ")", "DeserializeCellBlocks", "(", "pm", "proto", ".", "Message", ",", "b", "[", "]", "byte", ")", "(", "uint32", ",", "error", ")", "{", "resp", ":=", "pm", ".", "(", "*", "pb", ".", "MutateResponse", ")", "\n", ...
// DeserializeCellBlocks deserializes mutate result from cell blocks
[ "DeserializeCellBlocks", "deserializes", "mutate", "result", "from", "cell", "blocks" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/mutate.go#L385-L397
train
tsuna/gohbase
region/new.go
NewClient
func NewClient(ctx context.Context, addr string, ctype ClientType, queueSize int, flushInterval time.Duration, effectiveUser string, readTimeout time.Duration) (hrpc.RegionClient, error) { var d net.Dialer conn, err := d.DialContext(ctx, "tcp", addr) if err != nil { return nil, fmt.Errorf("failed to connect to the RegionServer at %s: %s", addr, err) } c := &client{ addr: addr, conn: conn, rpcs: make(chan hrpc.Call), done: make(chan struct{}), sent: make(map[uint32]hrpc.Call), rpcQueueSize: queueSize, flushInterval: flushInterval, effectiveUser: effectiveUser, readTimeout: readTimeout, } // time out send hello if it take long // TODO: do we even need to bother, we are going to retry anyway? if deadline, ok := ctx.Deadline(); ok { conn.SetWriteDeadline(deadline) } if err := c.sendHello(ctype); err != nil { conn.Close() return nil, fmt.Errorf("failed to send hello to the RegionServer at %s: %s", addr, err) } // reset write deadline conn.SetWriteDeadline(time.Time{}) if ctype == RegionClient { go c.processRPCs() // Batching goroutine } go c.receiveRPCs() // Reader goroutine return c, nil }
go
func NewClient(ctx context.Context, addr string, ctype ClientType, queueSize int, flushInterval time.Duration, effectiveUser string, readTimeout time.Duration) (hrpc.RegionClient, error) { var d net.Dialer conn, err := d.DialContext(ctx, "tcp", addr) if err != nil { return nil, fmt.Errorf("failed to connect to the RegionServer at %s: %s", addr, err) } c := &client{ addr: addr, conn: conn, rpcs: make(chan hrpc.Call), done: make(chan struct{}), sent: make(map[uint32]hrpc.Call), rpcQueueSize: queueSize, flushInterval: flushInterval, effectiveUser: effectiveUser, readTimeout: readTimeout, } // time out send hello if it take long // TODO: do we even need to bother, we are going to retry anyway? if deadline, ok := ctx.Deadline(); ok { conn.SetWriteDeadline(deadline) } if err := c.sendHello(ctype); err != nil { conn.Close() return nil, fmt.Errorf("failed to send hello to the RegionServer at %s: %s", addr, err) } // reset write deadline conn.SetWriteDeadline(time.Time{}) if ctype == RegionClient { go c.processRPCs() // Batching goroutine } go c.receiveRPCs() // Reader goroutine return c, nil }
[ "func", "NewClient", "(", "ctx", "context", ".", "Context", ",", "addr", "string", ",", "ctype", "ClientType", ",", "queueSize", "int", ",", "flushInterval", "time", ".", "Duration", ",", "effectiveUser", "string", ",", "readTimeout", "time", ".", "Duration", ...
// NewClient creates a new RegionClient.
[ "NewClient", "creates", "a", "new", "RegionClient", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/region/new.go#L20-L56
train
tsuna/gohbase
hrpc/query.go
newBaseQuery
func newBaseQuery() baseQuery { return baseQuery{ storeLimit: DefaultMaxResultsPerColumnFamily, fromTimestamp: MinTimestamp, toTimestamp: MaxTimestamp, maxVersions: DefaultMaxVersions, } }
go
func newBaseQuery() baseQuery { return baseQuery{ storeLimit: DefaultMaxResultsPerColumnFamily, fromTimestamp: MinTimestamp, toTimestamp: MaxTimestamp, maxVersions: DefaultMaxVersions, } }
[ "func", "newBaseQuery", "(", ")", "baseQuery", "{", "return", "baseQuery", "{", "storeLimit", ":", "DefaultMaxResultsPerColumnFamily", ",", "fromTimestamp", ":", "MinTimestamp", ",", "toTimestamp", ":", "MaxTimestamp", ",", "maxVersions", ":", "DefaultMaxVersions", ",...
// newBaseQuery return baseQuery with all default values
[ "newBaseQuery", "return", "baseQuery", "with", "all", "default", "values" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/query.go#L29-L36
train
tsuna/gohbase
hrpc/query.go
Families
func Families(f map[string][]string) func(Call) error { return func(hc Call) error { if c, ok := hc.(hasQueryOptions); ok { c.setFamilies(f) return nil } return errors.New("'Families' option can only be used with Get or Scan request") } }
go
func Families(f map[string][]string) func(Call) error { return func(hc Call) error { if c, ok := hc.(hasQueryOptions); ok { c.setFamilies(f) return nil } return errors.New("'Families' option can only be used with Get or Scan request") } }
[ "func", "Families", "(", "f", "map", "[", "string", "]", "[", "]", "string", ")", "func", "(", "Call", ")", "error", "{", "return", "func", "(", "hc", "Call", ")", "error", "{", "if", "c", ",", "ok", ":=", "hc", ".", "(", "hasQueryOptions", ")", ...
// Families option adds families constraint to a Scan or Get request.
[ "Families", "option", "adds", "families", "constraint", "to", "a", "Scan", "or", "Get", "request", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/query.go#L59-L67
train
tsuna/gohbase
hrpc/query.go
Filters
func Filters(f filter.Filter) func(Call) error { return func(hc Call) error { if c, ok := hc.(hasQueryOptions); ok { pbF, err := f.ConstructPBFilter() if err != nil { return err } c.setFilter(pbF) return nil } return errors.New("'Filters' option can only be used with Get or Scan request") } }
go
func Filters(f filter.Filter) func(Call) error { return func(hc Call) error { if c, ok := hc.(hasQueryOptions); ok { pbF, err := f.ConstructPBFilter() if err != nil { return err } c.setFilter(pbF) return nil } return errors.New("'Filters' option can only be used with Get or Scan request") } }
[ "func", "Filters", "(", "f", "filter", ".", "Filter", ")", "func", "(", "Call", ")", "error", "{", "return", "func", "(", "hc", "Call", ")", "error", "{", "if", "c", ",", "ok", ":=", "hc", ".", "(", "hasQueryOptions", ")", ";", "ok", "{", "pbF", ...
// Filters option adds filters constraint to a Scan or Get request.
[ "Filters", "option", "adds", "filters", "constraint", "to", "a", "Scan", "or", "Get", "request", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/query.go#L70-L82
train
tsuna/gohbase
hrpc/query.go
MaxVersions
func MaxVersions(versions uint32) func(Call) error { return func(hc Call) error { if c, ok := hc.(hasQueryOptions); ok { if versions > math.MaxInt32 { return errors.New("'MaxVersions' exceeds supported number of versions") } c.setMaxVersions(versions) return nil } return errors.New("'MaxVersions' option can only be used with Get or Scan request") } }
go
func MaxVersions(versions uint32) func(Call) error { return func(hc Call) error { if c, ok := hc.(hasQueryOptions); ok { if versions > math.MaxInt32 { return errors.New("'MaxVersions' exceeds supported number of versions") } c.setMaxVersions(versions) return nil } return errors.New("'MaxVersions' option can only be used with Get or Scan request") } }
[ "func", "MaxVersions", "(", "versions", "uint32", ")", "func", "(", "Call", ")", "error", "{", "return", "func", "(", "hc", "Call", ")", "error", "{", "if", "c", ",", "ok", ":=", "hc", ".", "(", "hasQueryOptions", ")", ";", "ok", "{", "if", "versio...
// MaxVersions is used as a parameter for request creation. // Adds MaxVersions constraint to a request.
[ "MaxVersions", "is", "used", "as", "a", "parameter", "for", "request", "creation", ".", "Adds", "MaxVersions", "constraint", "to", "a", "request", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/query.go#L110-L121
train
tsuna/gohbase
hrpc/query.go
MaxResultsPerColumnFamily
func MaxResultsPerColumnFamily(maxresults uint32) func(Call) error { return func(hc Call) error { if c, ok := hc.(hasQueryOptions); ok { if maxresults > math.MaxInt32 { return errors.New( "'MaxResultsPerColumnFamily' exceeds supported number of value results") } c.setMaxResultsPerColumnFamily(maxresults) return nil } return errors.New( "'MaxResultsPerColumnFamily' option can only be used with Get or Scan request") } }
go
func MaxResultsPerColumnFamily(maxresults uint32) func(Call) error { return func(hc Call) error { if c, ok := hc.(hasQueryOptions); ok { if maxresults > math.MaxInt32 { return errors.New( "'MaxResultsPerColumnFamily' exceeds supported number of value results") } c.setMaxResultsPerColumnFamily(maxresults) return nil } return errors.New( "'MaxResultsPerColumnFamily' option can only be used with Get or Scan request") } }
[ "func", "MaxResultsPerColumnFamily", "(", "maxresults", "uint32", ")", "func", "(", "Call", ")", "error", "{", "return", "func", "(", "hc", "Call", ")", "error", "{", "if", "c", ",", "ok", ":=", "hc", ".", "(", "hasQueryOptions", ")", ";", "ok", "{", ...
// MaxResultsPerColumnFamily is an option for Get or Scan requests that sets the maximum // number of cells returned per column family in a row.
[ "MaxResultsPerColumnFamily", "is", "an", "option", "for", "Get", "or", "Scan", "requests", "that", "sets", "the", "maximum", "number", "of", "cells", "returned", "per", "column", "family", "in", "a", "row", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/query.go#L125-L138
train
tsuna/gohbase
hrpc/query.go
ResultOffset
func ResultOffset(offset uint32) func(Call) error { return func(hc Call) error { if c, ok := hc.(hasQueryOptions); ok { if offset > math.MaxInt32 { return errors.New("'ResultOffset' exceeds supported offset value") } c.setResultOffset(offset) return nil } return errors.New("'ResultOffset' option can only be used with Get or Scan request") } }
go
func ResultOffset(offset uint32) func(Call) error { return func(hc Call) error { if c, ok := hc.(hasQueryOptions); ok { if offset > math.MaxInt32 { return errors.New("'ResultOffset' exceeds supported offset value") } c.setResultOffset(offset) return nil } return errors.New("'ResultOffset' option can only be used with Get or Scan request") } }
[ "func", "ResultOffset", "(", "offset", "uint32", ")", "func", "(", "Call", ")", "error", "{", "return", "func", "(", "hc", "Call", ")", "error", "{", "if", "c", ",", "ok", ":=", "hc", ".", "(", "hasQueryOptions", ")", ";", "ok", "{", "if", "offset"...
// ResultOffset is a option for Scan or Get requests that sets the offset for cells // within a column family.
[ "ResultOffset", "is", "a", "option", "for", "Scan", "or", "Get", "requests", "that", "sets", "the", "offset", "for", "cells", "within", "a", "column", "family", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/query.go#L142-L153
train
tsuna/gohbase
hrpc/status.go
NewClusterStatus
func NewClusterStatus() *ClusterStatus { return &ClusterStatus{ base{ ctx: context.Background(), table: []byte{}, resultch: make(chan RPCResult, 1), }, } }
go
func NewClusterStatus() *ClusterStatus { return &ClusterStatus{ base{ ctx: context.Background(), table: []byte{}, resultch: make(chan RPCResult, 1), }, } }
[ "func", "NewClusterStatus", "(", ")", "*", "ClusterStatus", "{", "return", "&", "ClusterStatus", "{", "base", "{", "ctx", ":", "context", ".", "Background", "(", ")", ",", "table", ":", "[", "]", "byte", "{", "}", ",", "resultch", ":", "make", "(", "...
// NewClusterStatus creates a new ClusterStatusStruct with default fields
[ "NewClusterStatus", "creates", "a", "new", "ClusterStatusStruct", "with", "default", "fields" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/status.go#L16-L24
train
tsuna/gohbase
hrpc/scan.go
baseScan
func baseScan(ctx context.Context, table []byte, options ...func(Call) error) (*Scan, error) { s := &Scan{ base: base{ table: table, ctx: ctx, resultch: make(chan RPCResult, 1), }, baseQuery: newBaseQuery(), scannerID: math.MaxUint64, maxResultSize: DefaultMaxResultSize, numberOfRows: DefaultNumberOfRows, reversed: false, } err := applyOptions(s, options...) if err != nil { return nil, err } return s, nil }
go
func baseScan(ctx context.Context, table []byte, options ...func(Call) error) (*Scan, error) { s := &Scan{ base: base{ table: table, ctx: ctx, resultch: make(chan RPCResult, 1), }, baseQuery: newBaseQuery(), scannerID: math.MaxUint64, maxResultSize: DefaultMaxResultSize, numberOfRows: DefaultNumberOfRows, reversed: false, } err := applyOptions(s, options...) if err != nil { return nil, err } return s, nil }
[ "func", "baseScan", "(", "ctx", "context", ".", "Context", ",", "table", "[", "]", "byte", ",", "options", "...", "func", "(", "Call", ")", "error", ")", "(", "*", "Scan", ",", "error", ")", "{", "s", ":=", "&", "Scan", "{", "base", ":", "base", ...
// baseScan returns a Scan struct with default values set.
[ "baseScan", "returns", "a", "Scan", "struct", "with", "default", "values", "set", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/scan.go#L74-L93
train
tsuna/gohbase
hrpc/scan.go
NewScan
func NewScan(ctx context.Context, table []byte, options ...func(Call) error) (*Scan, error) { return baseScan(ctx, table, options...) }
go
func NewScan(ctx context.Context, table []byte, options ...func(Call) error) (*Scan, error) { return baseScan(ctx, table, options...) }
[ "func", "NewScan", "(", "ctx", "context", ".", "Context", ",", "table", "[", "]", "byte", ",", "options", "...", "func", "(", "Call", ")", "error", ")", "(", "*", "Scan", ",", "error", ")", "{", "return", "baseScan", "(", "ctx", ",", "table", ",", ...
// NewScan creates a scanner for the given table.
[ "NewScan", "creates", "a", "scanner", "for", "the", "given", "table", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/scan.go#L105-L107
train
tsuna/gohbase
hrpc/scan.go
NewScanStr
func NewScanStr(ctx context.Context, table string, options ...func(Call) error) (*Scan, error) { return NewScan(ctx, []byte(table), options...) }
go
func NewScanStr(ctx context.Context, table string, options ...func(Call) error) (*Scan, error) { return NewScan(ctx, []byte(table), options...) }
[ "func", "NewScanStr", "(", "ctx", "context", ".", "Context", ",", "table", "string", ",", "options", "...", "func", "(", "Call", ")", "error", ")", "(", "*", "Scan", ",", "error", ")", "{", "return", "NewScan", "(", "ctx", ",", "[", "]", "byte", "(...
// NewScanStr creates a scanner for the given table.
[ "NewScanStr", "creates", "a", "scanner", "for", "the", "given", "table", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/scan.go#L125-L127
train
tsuna/gohbase
hrpc/scan.go
ToProto
func (s *Scan) ToProto() proto.Message { scan := &pb.ScanRequest{ Region: s.regionSpecifier(), CloseScanner: &s.closeScanner, NumberOfRows: &s.numberOfRows, // tell server that we can process results that are only part of a row ClientHandlesPartials: proto.Bool(true), // tell server that we "handle" heartbeats by ignoring them // since we don't really time out our scans (unless context was cancelled) ClientHandlesHeartbeats: proto.Bool(true), } if s.scannerID != math.MaxUint64 { scan.ScannerId = &s.scannerID return scan } scan.Scan = &pb.Scan{ Column: familiesToColumn(s.families), StartRow: s.startRow, StopRow: s.stopRow, TimeRange: &pb.TimeRange{}, MaxResultSize: &s.maxResultSize, } if s.maxVersions != DefaultMaxVersions { scan.Scan.MaxVersions = &s.maxVersions } /* added support for limit number of cells per row */ if s.storeLimit != DefaultMaxResultsPerColumnFamily { scan.Scan.StoreLimit = &s.storeLimit } if s.storeOffset != 0 { scan.Scan.StoreOffset = &s.storeOffset } if s.fromTimestamp != MinTimestamp { scan.Scan.TimeRange.From = &s.fromTimestamp } if s.toTimestamp != MaxTimestamp { scan.Scan.TimeRange.To = &s.toTimestamp } if s.reversed { scan.Scan.Reversed = &s.reversed } scan.Scan.Filter = s.filter return scan }
go
func (s *Scan) ToProto() proto.Message { scan := &pb.ScanRequest{ Region: s.regionSpecifier(), CloseScanner: &s.closeScanner, NumberOfRows: &s.numberOfRows, // tell server that we can process results that are only part of a row ClientHandlesPartials: proto.Bool(true), // tell server that we "handle" heartbeats by ignoring them // since we don't really time out our scans (unless context was cancelled) ClientHandlesHeartbeats: proto.Bool(true), } if s.scannerID != math.MaxUint64 { scan.ScannerId = &s.scannerID return scan } scan.Scan = &pb.Scan{ Column: familiesToColumn(s.families), StartRow: s.startRow, StopRow: s.stopRow, TimeRange: &pb.TimeRange{}, MaxResultSize: &s.maxResultSize, } if s.maxVersions != DefaultMaxVersions { scan.Scan.MaxVersions = &s.maxVersions } /* added support for limit number of cells per row */ if s.storeLimit != DefaultMaxResultsPerColumnFamily { scan.Scan.StoreLimit = &s.storeLimit } if s.storeOffset != 0 { scan.Scan.StoreOffset = &s.storeOffset } if s.fromTimestamp != MinTimestamp { scan.Scan.TimeRange.From = &s.fromTimestamp } if s.toTimestamp != MaxTimestamp { scan.Scan.TimeRange.To = &s.toTimestamp } if s.reversed { scan.Scan.Reversed = &s.reversed } scan.Scan.Filter = s.filter return scan }
[ "func", "(", "s", "*", "Scan", ")", "ToProto", "(", ")", "proto", ".", "Message", "{", "scan", ":=", "&", "pb", ".", "ScanRequest", "{", "Region", ":", "s", ".", "regionSpecifier", "(", ")", ",", "CloseScanner", ":", "&", "s", ".", "closeScanner", ...
// ToProto converts this Scan into a protobuf message
[ "ToProto", "converts", "this", "Scan", "into", "a", "protobuf", "message" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/scan.go#L174-L219
train
tsuna/gohbase
hrpc/scan.go
DeserializeCellBlocks
func (s *Scan) DeserializeCellBlocks(m proto.Message, b []byte) (uint32, error) { scanResp := m.(*pb.ScanResponse) partials := scanResp.GetPartialFlagPerResult() scanResp.Results = make([]*pb.Result, len(partials)) var readLen uint32 for i, numCells := range scanResp.GetCellsPerResult() { cells, l, err := deserializeCellBlocks(b[readLen:], numCells) if err != nil { return 0, err } scanResp.Results[i] = &pb.Result{ Cell: cells, Partial: proto.Bool(partials[i]), } readLen += l } return readLen, nil }
go
func (s *Scan) DeserializeCellBlocks(m proto.Message, b []byte) (uint32, error) { scanResp := m.(*pb.ScanResponse) partials := scanResp.GetPartialFlagPerResult() scanResp.Results = make([]*pb.Result, len(partials)) var readLen uint32 for i, numCells := range scanResp.GetCellsPerResult() { cells, l, err := deserializeCellBlocks(b[readLen:], numCells) if err != nil { return 0, err } scanResp.Results[i] = &pb.Result{ Cell: cells, Partial: proto.Bool(partials[i]), } readLen += l } return readLen, nil }
[ "func", "(", "s", "*", "Scan", ")", "DeserializeCellBlocks", "(", "m", "proto", ".", "Message", ",", "b", "[", "]", "byte", ")", "(", "uint32", ",", "error", ")", "{", "scanResp", ":=", "m", ".", "(", "*", "pb", ".", "ScanResponse", ")", "\n", "p...
// DeserializeCellBlocks deserializes scan results from cell blocks
[ "DeserializeCellBlocks", "deserializes", "scan", "results", "from", "cell", "blocks" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/scan.go#L228-L245
train
tsuna/gohbase
hrpc/scan.go
ScannerID
func ScannerID(id uint64) func(Call) error { return func(s Call) error { scan, ok := s.(*Scan) if !ok { return errors.New("'ScannerID' option can only be used with Scan queries") } scan.scannerID = id return nil } }
go
func ScannerID(id uint64) func(Call) error { return func(s Call) error { scan, ok := s.(*Scan) if !ok { return errors.New("'ScannerID' option can only be used with Scan queries") } scan.scannerID = id return nil } }
[ "func", "ScannerID", "(", "id", "uint64", ")", "func", "(", "Call", ")", "error", "{", "return", "func", "(", "s", "Call", ")", "error", "{", "scan", ",", "ok", ":=", "s", ".", "(", "*", "Scan", ")", "\n", "if", "!", "ok", "{", "return", "error...
// ScannerID is an option for scan requests. // This is an internal option to fetch the next set of results for an ongoing scan.
[ "ScannerID", "is", "an", "option", "for", "scan", "requests", ".", "This", "is", "an", "internal", "option", "to", "fetch", "the", "next", "set", "of", "results", "for", "an", "ongoing", "scan", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/scan.go#L249-L258
train
tsuna/gohbase
hrpc/scan.go
CloseScanner
func CloseScanner() func(Call) error { return func(s Call) error { scan, ok := s.(*Scan) if !ok { return errors.New("'Close' option can only be used with Scan queries") } scan.closeScanner = true return nil } }
go
func CloseScanner() func(Call) error { return func(s Call) error { scan, ok := s.(*Scan) if !ok { return errors.New("'Close' option can only be used with Scan queries") } scan.closeScanner = true return nil } }
[ "func", "CloseScanner", "(", ")", "func", "(", "Call", ")", "error", "{", "return", "func", "(", "s", "Call", ")", "error", "{", "scan", ",", "ok", ":=", "s", ".", "(", "*", "Scan", ")", "\n", "if", "!", "ok", "{", "return", "errors", ".", "New...
// CloseScanner is an option for scan requests. // Closes scanner after the first result is returned. This is an internal option // but could be useful if you know that your scan result fits into one response // in order to save an extra request.
[ "CloseScanner", "is", "an", "option", "for", "scan", "requests", ".", "Closes", "scanner", "after", "the", "first", "result", "is", "returned", ".", "This", "is", "an", "internal", "option", "but", "could", "be", "useful", "if", "you", "know", "that", "you...
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/scan.go#L264-L273
train
tsuna/gohbase
hrpc/scan.go
MaxResultSize
func MaxResultSize(n uint64) func(Call) error { return func(g Call) error { scan, ok := g.(*Scan) if !ok { return errors.New("'MaxResultSize' option can only be used with Scan queries") } if n == 0 { return errors.New("'MaxResultSize' option must be greater than 0") } scan.maxResultSize = n return nil } }
go
func MaxResultSize(n uint64) func(Call) error { return func(g Call) error { scan, ok := g.(*Scan) if !ok { return errors.New("'MaxResultSize' option can only be used with Scan queries") } if n == 0 { return errors.New("'MaxResultSize' option must be greater than 0") } scan.maxResultSize = n return nil } }
[ "func", "MaxResultSize", "(", "n", "uint64", ")", "func", "(", "Call", ")", "error", "{", "return", "func", "(", "g", "Call", ")", "error", "{", "scan", ",", "ok", ":=", "g", ".", "(", "*", "Scan", ")", "\n", "if", "!", "ok", "{", "return", "er...
// MaxResultSize is an option for scan requests. // Maximum number of bytes fetched when calling a scanner's next method. // MaxResultSize takes priority over NumberOfRows.
[ "MaxResultSize", "is", "an", "option", "for", "scan", "requests", ".", "Maximum", "number", "of", "bytes", "fetched", "when", "calling", "a", "scanner", "s", "next", "method", ".", "MaxResultSize", "takes", "priority", "over", "NumberOfRows", "." ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/scan.go#L278-L290
train
tsuna/gohbase
hrpc/scan.go
NumberOfRows
func NumberOfRows(n uint32) func(Call) error { return func(g Call) error { scan, ok := g.(*Scan) if !ok { return errors.New("'NumberOfRows' option can only be used with Scan queries") } scan.numberOfRows = n return nil } }
go
func NumberOfRows(n uint32) func(Call) error { return func(g Call) error { scan, ok := g.(*Scan) if !ok { return errors.New("'NumberOfRows' option can only be used with Scan queries") } scan.numberOfRows = n return nil } }
[ "func", "NumberOfRows", "(", "n", "uint32", ")", "func", "(", "Call", ")", "error", "{", "return", "func", "(", "g", "Call", ")", "error", "{", "scan", ",", "ok", ":=", "g", ".", "(", "*", "Scan", ")", "\n", "if", "!", "ok", "{", "return", "err...
// NumberOfRows is an option for scan requests. // Specifies how many rows are fetched with each request to regionserver. // Should be > 0, avoid extremely low values such as 1 because a request // to regionserver will be made for every row.
[ "NumberOfRows", "is", "an", "option", "for", "scan", "requests", ".", "Specifies", "how", "many", "rows", "are", "fetched", "with", "each", "request", "to", "regionserver", ".", "Should", "be", ">", "0", "avoid", "extremely", "low", "values", "such", "as", ...
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/scan.go#L296-L305
train
tsuna/gohbase
hrpc/scan.go
Reversed
func Reversed() func(Call) error { return func(g Call) error { scan, ok := g.(*Scan) if !ok { return errors.New("'Reversed' option can only be used with Scan queries") } scan.reversed = true return nil } }
go
func Reversed() func(Call) error { return func(g Call) error { scan, ok := g.(*Scan) if !ok { return errors.New("'Reversed' option can only be used with Scan queries") } scan.reversed = true return nil } }
[ "func", "Reversed", "(", ")", "func", "(", "Call", ")", "error", "{", "return", "func", "(", "g", "Call", ")", "error", "{", "scan", ",", "ok", ":=", "g", ".", "(", "*", "Scan", ")", "\n", "if", "!", "ok", "{", "return", "errors", ".", "New", ...
// Reversed is a Scan-only option which allows you to scan in reverse key order // To use it the startKey would be greater than the end key
[ "Reversed", "is", "a", "Scan", "-", "only", "option", "which", "allows", "you", "to", "scan", "in", "reverse", "key", "order", "To", "use", "it", "the", "startKey", "would", "be", "greater", "than", "the", "end", "key" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/hrpc/scan.go#L324-L333
train
tsuna/gohbase
admin_client.go
ClusterStatus
func (c *client) ClusterStatus() (*pb.ClusterStatus, error) { pbmsg, err := c.SendRPC(hrpc.NewClusterStatus()) if err != nil { return nil, err } r, ok := pbmsg.(*pb.GetClusterStatusResponse) if !ok { return nil, fmt.Errorf("sendRPC returned not a ClusterStatusResponse") } return r.GetClusterStatus(), nil }
go
func (c *client) ClusterStatus() (*pb.ClusterStatus, error) { pbmsg, err := c.SendRPC(hrpc.NewClusterStatus()) if err != nil { return nil, err } r, ok := pbmsg.(*pb.GetClusterStatusResponse) if !ok { return nil, fmt.Errorf("sendRPC returned not a ClusterStatusResponse") } return r.GetClusterStatus(), nil }
[ "func", "(", "c", "*", "client", ")", "ClusterStatus", "(", ")", "(", "*", "pb", ".", "ClusterStatus", ",", "error", ")", "{", "pbmsg", ",", "err", ":=", "c", ".", "SendRPC", "(", "hrpc", ".", "NewClusterStatus", "(", ")", ")", "\n", "if", "err", ...
//Get the status of the cluster
[ "Get", "the", "status", "of", "the", "cluster" ]
24ffed0537aae38093b39c12781e4c09f8cb0029
https://github.com/tsuna/gohbase/blob/24ffed0537aae38093b39c12781e4c09f8cb0029/admin_client.go#L58-L70
train
y0ssar1an/q
args.go
argWidth
func argWidth(arg string) int { // Strip zero-width characters. replacer := strings.NewReplacer( "\n", "", "\t", "", "\r", "", "\f", "", "\v", "", string(bold), "", string(yellow), "", string(cyan), "", string(endColor), "", ) s := replacer.Replace(arg) return utf8.RuneCountInString(s) }
go
func argWidth(arg string) int { // Strip zero-width characters. replacer := strings.NewReplacer( "\n", "", "\t", "", "\r", "", "\f", "", "\v", "", string(bold), "", string(yellow), "", string(cyan), "", string(endColor), "", ) s := replacer.Replace(arg) return utf8.RuneCountInString(s) }
[ "func", "argWidth", "(", "arg", "string", ")", "int", "{", "// Strip zero-width characters.", "replacer", ":=", "strings", ".", "NewReplacer", "(", "\"", "\\n", "\"", ",", "\"", "\"", ",", "\"", "\\t", "\"", ",", "\"", "\"", ",", "\"", "\\r", "\"", ","...
// argWidth returns the number of characters that will be seen when the given // argument is printed at the terminal.
[ "argWidth", "returns", "the", "number", "of", "characters", "that", "will", "be", "seen", "when", "the", "given", "argument", "is", "printed", "at", "the", "terminal", "." ]
befa58832e0b7483b4246ec6b31c007e0a358353
https://github.com/y0ssar1an/q/blob/befa58832e0b7483b4246ec6b31c007e0a358353/args.go#L90-L105
train
y0ssar1an/q
args.go
colorize
func colorize(text string, c color) string { return string(c) + text + string(endColor) }
go
func colorize(text string, c color) string { return string(c) + text + string(endColor) }
[ "func", "colorize", "(", "text", "string", ",", "c", "color", ")", "string", "{", "return", "string", "(", "c", ")", "+", "text", "+", "string", "(", "endColor", ")", "\n", "}" ]
// colorize returns the given text encapsulated in ANSI escape codes that // give the text color in the terminal.
[ "colorize", "returns", "the", "given", "text", "encapsulated", "in", "ANSI", "escape", "codes", "that", "give", "the", "text", "color", "in", "the", "terminal", "." ]
befa58832e0b7483b4246ec6b31c007e0a358353
https://github.com/y0ssar1an/q/blob/befa58832e0b7483b4246ec6b31c007e0a358353/args.go#L109-L111
train
y0ssar1an/q
args.go
formatArgs
func formatArgs(args ...interface{}) []string { formatted := make([]string, 0, len(args)) for _, a := range args { s := colorize(pretty.Sprint(a), cyan) formatted = append(formatted, s) } return formatted }
go
func formatArgs(args ...interface{}) []string { formatted := make([]string, 0, len(args)) for _, a := range args { s := colorize(pretty.Sprint(a), cyan) formatted = append(formatted, s) } return formatted }
[ "func", "formatArgs", "(", "args", "...", "interface", "{", "}", ")", "[", "]", "string", "{", "formatted", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "args", ")", ")", "\n", "for", "_", ",", "a", ":=", "range", "args", "...
// formatArgs converts the given args to pretty-printed, colorized strings.
[ "formatArgs", "converts", "the", "given", "args", "to", "pretty", "-", "printed", "colorized", "strings", "." ]
befa58832e0b7483b4246ec6b31c007e0a358353
https://github.com/y0ssar1an/q/blob/befa58832e0b7483b4246ec6b31c007e0a358353/args.go#L127-L134
train
y0ssar1an/q
logger.go
flush
func (l *logger) flush() (err error) { path := filepath.Join(os.TempDir(), "q") f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600) if err != nil { return fmt.Errorf("failed to open %q: %v", path, err) } defer func() { if cerr := f.Close(); err == nil { err = cerr } l.lastWrite = time.Now() }() _, err = io.Copy(f, &l.buf) l.buf.Reset() if err != nil { return fmt.Errorf("failed to flush q buffer: %v", err) } return nil }
go
func (l *logger) flush() (err error) { path := filepath.Join(os.TempDir(), "q") f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600) if err != nil { return fmt.Errorf("failed to open %q: %v", path, err) } defer func() { if cerr := f.Close(); err == nil { err = cerr } l.lastWrite = time.Now() }() _, err = io.Copy(f, &l.buf) l.buf.Reset() if err != nil { return fmt.Errorf("failed to flush q buffer: %v", err) } return nil }
[ "func", "(", "l", "*", "logger", ")", "flush", "(", ")", "(", "err", "error", ")", "{", "path", ":=", "filepath", ".", "Join", "(", "os", ".", "TempDir", "(", ")", ",", "\"", "\"", ")", "\n", "f", ",", "err", ":=", "os", ".", "OpenFile", "(",...
// flush writes the logger's buffer to disk.
[ "flush", "writes", "the", "logger", "s", "buffer", "to", "disk", "." ]
befa58832e0b7483b4246ec6b31c007e0a358353
https://github.com/y0ssar1an/q/blob/befa58832e0b7483b4246ec6b31c007e0a358353/logger.go#L74-L94
train
xyproto/permissions2
permissions.go
AddAdminPath
func (perm *Permissions) AddAdminPath(prefix string) { perm.adminPathPrefixes = append(perm.adminPathPrefixes, prefix) }
go
func (perm *Permissions) AddAdminPath(prefix string) { perm.adminPathPrefixes = append(perm.adminPathPrefixes, prefix) }
[ "func", "(", "perm", "*", "Permissions", ")", "AddAdminPath", "(", "prefix", "string", ")", "{", "perm", ".", "adminPathPrefixes", "=", "append", "(", "perm", ".", "adminPathPrefixes", ",", "prefix", ")", "\n", "}" ]
// AddAdminPath registers a path prefix for URLs that shall only be reached by logged in administrators
[ "AddAdminPath", "registers", "a", "path", "prefix", "for", "URLs", "that", "shall", "only", "be", "reached", "by", "logged", "in", "administrators" ]
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/permissions.go#L92-L94
train
xyproto/permissions2
permissions.go
AddUserPath
func (perm *Permissions) AddUserPath(prefix string) { perm.userPathPrefixes = append(perm.userPathPrefixes, prefix) }
go
func (perm *Permissions) AddUserPath(prefix string) { perm.userPathPrefixes = append(perm.userPathPrefixes, prefix) }
[ "func", "(", "perm", "*", "Permissions", ")", "AddUserPath", "(", "prefix", "string", ")", "{", "perm", ".", "userPathPrefixes", "=", "append", "(", "perm", ".", "userPathPrefixes", ",", "prefix", ")", "\n", "}" ]
// AddUserPath registers a path prefix for URLs that shall only be reached by logged in users
[ "AddUserPath", "registers", "a", "path", "prefix", "for", "URLs", "that", "shall", "only", "be", "reached", "by", "logged", "in", "users" ]
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/permissions.go#L97-L99
train
xyproto/permissions2
permissions.go
AddPublicPath
func (perm *Permissions) AddPublicPath(prefix string) { perm.publicPathPrefixes = append(perm.publicPathPrefixes, prefix) }
go
func (perm *Permissions) AddPublicPath(prefix string) { perm.publicPathPrefixes = append(perm.publicPathPrefixes, prefix) }
[ "func", "(", "perm", "*", "Permissions", ")", "AddPublicPath", "(", "prefix", "string", ")", "{", "perm", ".", "publicPathPrefixes", "=", "append", "(", "perm", ".", "publicPathPrefixes", ",", "prefix", ")", "\n", "}" ]
// AddPublicPath registers a path prefix for URLs that can be reached by anyone
[ "AddPublicPath", "registers", "a", "path", "prefix", "for", "URLs", "that", "can", "be", "reached", "by", "anyone" ]
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/permissions.go#L102-L104
train
xyproto/permissions2
permissions.go
PermissionDenied
func PermissionDenied(w http.ResponseWriter, req *http.Request) { http.Error(w, "Permission denied.", http.StatusForbidden) }
go
func PermissionDenied(w http.ResponseWriter, req *http.Request) { http.Error(w, "Permission denied.", http.StatusForbidden) }
[ "func", "PermissionDenied", "(", "w", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "http", ".", "Error", "(", "w", ",", "\"", "\"", ",", "http", ".", "StatusForbidden", ")", "\n", "}" ]
// The default "permission denied" http handler.
[ "The", "default", "permission", "denied", "http", "handler", "." ]
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/permissions.go#L122-L124
train
xyproto/permissions2
hashing.go
hashBcrypt
func hashBcrypt(password string) []byte { hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) if err != nil { panic("Permissions: bcrypt password hashing unsuccessful") } return hash }
go
func hashBcrypt(password string) []byte { hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) if err != nil { panic("Permissions: bcrypt password hashing unsuccessful") } return hash }
[ "func", "hashBcrypt", "(", "password", "string", ")", "[", "]", "byte", "{", "hash", ",", "err", ":=", "bcrypt", ".", "GenerateFromPassword", "(", "[", "]", "byte", "(", "password", ")", ",", "bcrypt", ".", "DefaultCost", ")", "\n", "if", "err", "!=", ...
// Hash the password with bcrypt
[ "Hash", "the", "password", "with", "bcrypt" ]
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/hashing.go#L20-L26
train
xyproto/permissions2
hashing.go
correctBcrypt
func correctBcrypt(hash []byte, password string) bool { // prevents timing attack return bcrypt.CompareHashAndPassword(hash, []byte(password)) == nil }
go
func correctBcrypt(hash []byte, password string) bool { // prevents timing attack return bcrypt.CompareHashAndPassword(hash, []byte(password)) == nil }
[ "func", "correctBcrypt", "(", "hash", "[", "]", "byte", ",", "password", "string", ")", "bool", "{", "// prevents timing attack", "return", "bcrypt", ".", "CompareHashAndPassword", "(", "hash", ",", "[", "]", "byte", "(", "password", ")", ")", "==", "nil", ...
// Check if a given password is correct, for a given bcrypt hash
[ "Check", "if", "a", "given", "password", "is", "correct", "for", "a", "given", "bcrypt", "hash" ]
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/hashing.go#L40-L43
train
xyproto/permissions2
userstate.go
NewUserStateWithPassword
func NewUserStateWithPassword(hostname, password string) *UserState { // db index 0, initialize random generator after generating the cookie secret, password var connectTo string switch { case (password == "") && (strings.Count(hostname, ":") == 0): connectTo = hostname + ":6379" case strings.Count(hostname, ":") > 0: connectTo = password + "@" + hostname default: connectTo = password + "@" + hostname + ":6379" } // Create a new UserState with database index 0, "true" for seeding the // random number generator and host string return NewUserState(0, true, connectTo) }
go
func NewUserStateWithPassword(hostname, password string) *UserState { // db index 0, initialize random generator after generating the cookie secret, password var connectTo string switch { case (password == "") && (strings.Count(hostname, ":") == 0): connectTo = hostname + ":6379" case strings.Count(hostname, ":") > 0: connectTo = password + "@" + hostname default: connectTo = password + "@" + hostname + ":6379" } // Create a new UserState with database index 0, "true" for seeding the // random number generator and host string return NewUserState(0, true, connectTo) }
[ "func", "NewUserStateWithPassword", "(", "hostname", ",", "password", "string", ")", "*", "UserState", "{", "// db index 0, initialize random generator after generating the cookie secret, password", "var", "connectTo", "string", "\n", "switch", "{", "case", "(", "password", ...
// Same as NewUserStateSimple, but takes a hostname and a password. // Use NewUserState for control over the database index and port number. // Calls log.Fatal if things go wrong.
[ "Same", "as", "NewUserStateSimple", "but", "takes", "a", "hostname", "and", "a", "password", ".", "Use", "NewUserState", "for", "control", "over", "the", "database", "index", "and", "port", "number", ".", "Calls", "log", ".", "Fatal", "if", "things", "go", ...
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/userstate.go#L63-L77
train
xyproto/permissions2
userstate.go
NewUserStateWithPassword2
func NewUserStateWithPassword2(hostname, password string) (*UserState, error) { // db index 0, initialize random generator after generating the cookie secret, password var connectTo string if (password == "") && (strings.Count(hostname, ":") == 0) { connectTo = hostname + ":6379" } else if strings.Count(hostname, ":") > 0 { connectTo = password + "@" + hostname } else { connectTo = password + "@" + hostname + ":6379" } // Create a new UserState with database index 0, "true" for seeding the // random number generator and host string return NewUserState2(0, true, connectTo) }
go
func NewUserStateWithPassword2(hostname, password string) (*UserState, error) { // db index 0, initialize random generator after generating the cookie secret, password var connectTo string if (password == "") && (strings.Count(hostname, ":") == 0) { connectTo = hostname + ":6379" } else if strings.Count(hostname, ":") > 0 { connectTo = password + "@" + hostname } else { connectTo = password + "@" + hostname + ":6379" } // Create a new UserState with database index 0, "true" for seeding the // random number generator and host string return NewUserState2(0, true, connectTo) }
[ "func", "NewUserStateWithPassword2", "(", "hostname", ",", "password", "string", ")", "(", "*", "UserState", ",", "error", ")", "{", "// db index 0, initialize random generator after generating the cookie secret, password", "var", "connectTo", "string", "\n", "if", "(", "...
// Same as NewUserStateSimple, but takes a hostname and a password. // Use NewUserState for control over the database index and port number. // Returns an error if things go wrong.
[ "Same", "as", "NewUserStateSimple", "but", "takes", "a", "hostname", "and", "a", "password", ".", "Use", "NewUserState", "for", "control", "over", "the", "database", "index", "and", "port", "number", ".", "Returns", "an", "error", "if", "things", "go", "wron...
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/userstate.go#L82-L95
train
xyproto/permissions2
userstate.go
HasUser
func (state *UserState) HasUser(username string) bool { val, err := state.usernames.Has(username) if err != nil { // This happened at concurrent connections before introducing the connection pool panic("ERROR: Lost connection to Redis?") } return val }
go
func (state *UserState) HasUser(username string) bool { val, err := state.usernames.Has(username) if err != nil { // This happened at concurrent connections before introducing the connection pool panic("ERROR: Lost connection to Redis?") } return val }
[ "func", "(", "state", "*", "UserState", ")", "HasUser", "(", "username", "string", ")", "bool", "{", "val", ",", "err", ":=", "state", ".", "usernames", ".", "Has", "(", "username", ")", "\n", "if", "err", "!=", "nil", "{", "// This happened at concurren...
// HasUser checks if the given username exists.
[ "HasUser", "checks", "if", "the", "given", "username", "exists", "." ]
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/userstate.go#L259-L266
train
xyproto/permissions2
userstate.go
HasUser2
func (state *UserState) HasUser2(username string) (bool, error) { val, err := state.usernames.Has(username) if err != nil { // This happened at concurrent connections before introducing the connection pool return false, errors.New("Lost connection to Redis?") } return val, nil }
go
func (state *UserState) HasUser2(username string) (bool, error) { val, err := state.usernames.Has(username) if err != nil { // This happened at concurrent connections before introducing the connection pool return false, errors.New("Lost connection to Redis?") } return val, nil }
[ "func", "(", "state", "*", "UserState", ")", "HasUser2", "(", "username", "string", ")", "(", "bool", ",", "error", ")", "{", "val", ",", "err", ":=", "state", ".", "usernames", ".", "Has", "(", "username", ")", "\n", "if", "err", "!=", "nil", "{",...
// HasUser2 checks if the given username exists.
[ "HasUser2", "checks", "if", "the", "given", "username", "exists", "." ]
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/userstate.go#L269-L276
train
xyproto/permissions2
userstate.go
BooleanField
func (state *UserState) BooleanField(username, fieldname string) bool { hasUser := state.HasUser(username) if !hasUser { return false } value, err := state.users.Get(username, fieldname) if err != nil { return false } return value == "true" }
go
func (state *UserState) BooleanField(username, fieldname string) bool { hasUser := state.HasUser(username) if !hasUser { return false } value, err := state.users.Get(username, fieldname) if err != nil { return false } return value == "true" }
[ "func", "(", "state", "*", "UserState", ")", "BooleanField", "(", "username", ",", "fieldname", "string", ")", "bool", "{", "hasUser", ":=", "state", ".", "HasUser", "(", "username", ")", "\n", "if", "!", "hasUser", "{", "return", "false", "\n", "}", "...
// BooleanField returns the boolean value for a given username and field name. // If the user or field is missing, false will be returned. // Useful for states where it makes sense that the returned value is not true // unless everything is in order.
[ "BooleanField", "returns", "the", "boolean", "value", "for", "a", "given", "username", "and", "field", "name", ".", "If", "the", "user", "or", "field", "is", "missing", "false", "will", "be", "returned", ".", "Useful", "for", "states", "where", "it", "make...
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/userstate.go#L304-L314
train
xyproto/permissions2
userstate.go
SetBooleanField
func (state *UserState) SetBooleanField(username, fieldname string, val bool) { strval := "false" if val { strval = "true" } state.users.Set(username, fieldname, strval) }
go
func (state *UserState) SetBooleanField(username, fieldname string, val bool) { strval := "false" if val { strval = "true" } state.users.Set(username, fieldname, strval) }
[ "func", "(", "state", "*", "UserState", ")", "SetBooleanField", "(", "username", ",", "fieldname", "string", ",", "val", "bool", ")", "{", "strval", ":=", "\"", "\"", "\n", "if", "val", "{", "strval", "=", "\"", "\"", "\n", "}", "\n", "state", ".", ...
// Store a boolean value for the given username and custom fieldname.
[ "Store", "a", "boolean", "value", "for", "the", "given", "username", "and", "custom", "fieldname", "." ]
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/userstate.go#L317-L323
train
xyproto/permissions2
userstate.go
IsLoggedIn
func (state *UserState) IsLoggedIn(username string) bool { if !state.HasUser(username) { return false } status, err := state.users.Get(username, "loggedin") if err != nil { // Returns "no" if the status can not be retrieved return false } return status == "true" }
go
func (state *UserState) IsLoggedIn(username string) bool { if !state.HasUser(username) { return false } status, err := state.users.Get(username, "loggedin") if err != nil { // Returns "no" if the status can not be retrieved return false } return status == "true" }
[ "func", "(", "state", "*", "UserState", ")", "IsLoggedIn", "(", "username", "string", ")", "bool", "{", "if", "!", "state", ".", "HasUser", "(", "username", ")", "{", "return", "false", "\n", "}", "\n", "status", ",", "err", ":=", "state", ".", "user...
// IsLoggedIn checks if the given username is logged in.
[ "IsLoggedIn", "checks", "if", "the", "given", "username", "is", "logged", "in", "." ]
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/userstate.go#L331-L341
train
xyproto/permissions2
userstate.go
AdminRights
func (state *UserState) AdminRights(req *http.Request) bool { username, err := state.UsernameCookie(req) if err != nil { return false } return state.IsLoggedIn(username) && state.IsAdmin(username) }
go
func (state *UserState) AdminRights(req *http.Request) bool { username, err := state.UsernameCookie(req) if err != nil { return false } return state.IsLoggedIn(username) && state.IsAdmin(username) }
[ "func", "(", "state", "*", "UserState", ")", "AdminRights", "(", "req", "*", "http", ".", "Request", ")", "bool", "{", "username", ",", "err", ":=", "state", ".", "UsernameCookie", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fals...
// AdminRights checks if the current user is logged in and has administrator rights.
[ "AdminRights", "checks", "if", "the", "current", "user", "is", "logged", "in", "and", "has", "administrator", "rights", "." ]
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/userstate.go#L344-L350
train
xyproto/permissions2
userstate.go
Email
func (state *UserState) Email(username string) (string, error) { return state.users.Get(username, "email") }
go
func (state *UserState) Email(username string) (string, error) { return state.users.Get(username, "email") }
[ "func", "(", "state", "*", "UserState", ")", "Email", "(", "username", "string", ")", "(", "string", ",", "error", ")", "{", "return", "state", ".", "users", ".", "Get", "(", "username", ",", "\"", "\"", ")", "\n", "}" ]
// Email returns the email address for the given username.
[ "Email", "returns", "the", "email", "address", "for", "the", "given", "username", "." ]
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/userstate.go#L424-L426
train
xyproto/permissions2
userstate.go
PasswordHash
func (state *UserState) PasswordHash(username string) (string, error) { return state.users.Get(username, "password") }
go
func (state *UserState) PasswordHash(username string) (string, error) { return state.users.Get(username, "password") }
[ "func", "(", "state", "*", "UserState", ")", "PasswordHash", "(", "username", "string", ")", "(", "string", ",", "error", ")", "{", "return", "state", ".", "users", ".", "Get", "(", "username", ",", "\"", "\"", ")", "\n", "}" ]
// PasswordHash returns the password hash for the given username.
[ "PasswordHash", "returns", "the", "password", "hash", "for", "the", "given", "username", "." ]
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/userstate.go#L429-L431
train
xyproto/permissions2
userstate.go
ConfirmationCode
func (state *UserState) ConfirmationCode(username string) (string, error) { return state.users.Get(username, "confirmationCode") }
go
func (state *UserState) ConfirmationCode(username string) (string, error) { return state.users.Get(username, "confirmationCode") }
[ "func", "(", "state", "*", "UserState", ")", "ConfirmationCode", "(", "username", "string", ")", "(", "string", ",", "error", ")", "{", "return", "state", ".", "users", ".", "Get", "(", "username", ",", "\"", "\"", ")", "\n", "}" ]
// ConfirmationCode gets the confirmation code for a specific user.
[ "ConfirmationCode", "gets", "the", "confirmation", "code", "for", "a", "specific", "user", "." ]
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/userstate.go#L439-L441
train
xyproto/permissions2
userstate.go
AddUnconfirmed
func (state *UserState) AddUnconfirmed(username, confirmationCode string) { state.unconfirmed.Add(username) state.users.Set(username, "confirmationCode", confirmationCode) }
go
func (state *UserState) AddUnconfirmed(username, confirmationCode string) { state.unconfirmed.Add(username) state.users.Set(username, "confirmationCode", confirmationCode) }
[ "func", "(", "state", "*", "UserState", ")", "AddUnconfirmed", "(", "username", ",", "confirmationCode", "string", ")", "{", "state", ".", "unconfirmed", ".", "Add", "(", "username", ")", "\n", "state", ".", "users", ".", "Set", "(", "username", ",", "\"...
// AddUnconfirmed adds a user that is registered but not confirmed.
[ "AddUnconfirmed", "adds", "a", "user", "that", "is", "registered", "but", "not", "confirmed", "." ]
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/userstate.go#L449-L452
train
xyproto/permissions2
userstate.go
RemoveUnconfirmed
func (state *UserState) RemoveUnconfirmed(username string) { state.unconfirmed.Del(username) state.users.DelKey(username, "confirmationCode") }
go
func (state *UserState) RemoveUnconfirmed(username string) { state.unconfirmed.Del(username) state.users.DelKey(username, "confirmationCode") }
[ "func", "(", "state", "*", "UserState", ")", "RemoveUnconfirmed", "(", "username", "string", ")", "{", "state", ".", "unconfirmed", ".", "Del", "(", "username", ")", "\n", "state", ".", "users", ".", "DelKey", "(", "username", ",", "\"", "\"", ")", "\n...
// RemoveUnconfirmed removes a user that is registered but not confirmed.
[ "RemoveUnconfirmed", "removes", "a", "user", "that", "is", "registered", "but", "not", "confirmed", "." ]
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/userstate.go#L455-L458
train
xyproto/permissions2
userstate.go
RemoveUser
func (state *UserState) RemoveUser(username string) { state.usernames.Del(username) // Remove additional data as well // TODO: Ideally, remove all keys belonging to the user. state.users.DelKey(username, "loggedin") }
go
func (state *UserState) RemoveUser(username string) { state.usernames.Del(username) // Remove additional data as well // TODO: Ideally, remove all keys belonging to the user. state.users.DelKey(username, "loggedin") }
[ "func", "(", "state", "*", "UserState", ")", "RemoveUser", "(", "username", "string", ")", "{", "state", ".", "usernames", ".", "Del", "(", "username", ")", "\n", "// Remove additional data as well", "// TODO: Ideally, remove all keys belonging to the user.", "state", ...
// RemoveUser removes user and login status.
[ "RemoveUser", "removes", "user", "and", "login", "status", "." ]
f47b0751729e767ee4c9dcc64a00e4720b95c8e0
https://github.com/xyproto/permissions2/blob/f47b0751729e767ee4c9dcc64a00e4720b95c8e0/userstate.go#L466-L471
train