repo stringlengths 5 67 | sha stringlengths 40 40 | path stringlengths 4 234 | url stringlengths 85 339 | language stringclasses 6 values | split stringclasses 3 values | doc stringlengths 3 51.2k | sign stringlengths 5 8.01k | problem stringlengths 13 51.2k | output stringlengths 0 3.87M |
|---|---|---|---|---|---|---|---|---|---|
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | caching/generic_storage.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/caching/generic_storage.go#L59-L71 | go | train | // This creates a GenericStorage. See GenericStorageOptions for additional
// information. | func NewGenericStorage(name string, options GenericStorageOptions) Storage | // This creates a GenericStorage. See GenericStorageOptions for additional
// information.
func NewGenericStorage(name string, options GenericStorageOptions) Storage | {
return &GenericStorage{
name: name,
get: options.GetFunc,
getMulti: options.GetMultiFunc,
set: options.SetFunc,
setMulti: options.SetMultiFunc,
del: options.DelFunc,
delMulti: options.DelMultiFunc,
errorOnFlush: options.ErrorOnFlush,
flush: options.FlushFunc,
}
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | caching/generic_storage.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/caching/generic_storage.go#L74-L93 | go | train | // See Storage/GenericStorageOptions for documentation. | func (s *GenericStorage) Get(key interface{}) (interface{}, error) | // See Storage/GenericStorageOptions for documentation.
func (s *GenericStorage) Get(key interface{}) (interface{}, error) | {
if s.get == nil && s.getMulti == nil {
return nil, errors.Newf(
"'%s' does not have Get/GetMulti implementation",
s.name)
}
s.rwMutex.RLock()
defer s.rwMutex.RUnlock()
if s.get != nil {
return s.get(key)
}
items, err := s.getMulti(key)
if err != nil {
return nil, err
}
return items[0], nil
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | caching/generic_storage.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/caching/generic_storage.go#L96-L119 | go | train | // See Storage/GenericStorageOptions for documentation. | func (s *GenericStorage) GetMulti(keys ...interface{}) ([]interface{}, error) | // See Storage/GenericStorageOptions for documentation.
func (s *GenericStorage) GetMulti(keys ...interface{}) ([]interface{}, error) | {
if s.get == nil && s.getMulti == nil {
return nil, errors.Newf(
"'%s' does not have Get/GetMulti implementation",
s.name)
}
s.rwMutex.RLock()
defer s.rwMutex.RUnlock()
if s.getMulti != nil {
return s.getMulti(keys...)
}
results := make([]interface{}, len(keys))
for i, key := range keys {
item, err := s.get(key)
if err != nil {
return nil, err
}
results[i] = item
}
return results, nil
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | caching/generic_storage.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/caching/generic_storage.go#L122-L136 | go | train | // See Storage/GenericStorageOptions for documentation. | func (s *GenericStorage) Set(item interface{}) error | // See Storage/GenericStorageOptions for documentation.
func (s *GenericStorage) Set(item interface{}) error | {
if s.set == nil && s.setMulti == nil {
return errors.Newf(
"'%s' does not have Set/SetMulti implementation",
s.name)
}
s.rwMutex.Lock()
defer s.rwMutex.Unlock()
if s.set != nil {
return s.set(item)
}
return s.setMulti(item)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | caching/generic_storage.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/caching/generic_storage.go#L139-L159 | go | train | // See Storage/GenericStorageOptions for documentation. | func (s *GenericStorage) SetMulti(items ...interface{}) error | // See Storage/GenericStorageOptions for documentation.
func (s *GenericStorage) SetMulti(items ...interface{}) error | {
if s.set == nil && s.setMulti == nil {
return errors.Newf(
"'%s' does not have Set/SetMulti implementation",
s.name)
}
s.rwMutex.Lock()
defer s.rwMutex.Unlock()
if s.setMulti != nil {
return s.setMulti(items...)
}
for _, item := range items {
if err := s.set(item); err != nil {
return err
}
}
return nil
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | caching/generic_storage.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/caching/generic_storage.go#L162-L176 | go | train | // See Storage/GenericStorageOptions for documentation. | func (s *GenericStorage) Delete(key interface{}) error | // See Storage/GenericStorageOptions for documentation.
func (s *GenericStorage) Delete(key interface{}) error | {
if s.del == nil && s.delMulti == nil {
return errors.Newf(
"'%s' does not have Delete/DeleteMulti implementation",
s.name)
}
s.rwMutex.Lock()
defer s.rwMutex.Unlock()
if s.del != nil {
return s.del(key)
}
return s.delMulti(key)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | caching/generic_storage.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/caching/generic_storage.go#L179-L199 | go | train | // See Storage/GenericStorageOptions for documentation. | func (s *GenericStorage) DeleteMulti(keys ...interface{}) error | // See Storage/GenericStorageOptions for documentation.
func (s *GenericStorage) DeleteMulti(keys ...interface{}) error | {
if s.del == nil && s.delMulti == nil {
return errors.Newf(
"'%s' does not have Delete/DeleteMulti implementation",
s.name)
}
s.rwMutex.Lock()
defer s.rwMutex.Unlock()
if s.delMulti != nil {
return s.delMulti(keys...)
}
for _, key := range keys {
if err := s.del(key); err != nil {
return err
}
}
return nil
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | caching/generic_storage.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/caching/generic_storage.go#L202-L215 | go | train | // See Storage/GenericStorageOptions for documentation. | func (s *GenericStorage) Flush() error | // See Storage/GenericStorageOptions for documentation.
func (s *GenericStorage) Flush() error | {
if s.errorOnFlush {
return errors.Newf("'%s' does not support Flush", s.name)
}
if s.flush == nil {
return nil
}
s.rwMutex.Lock()
defer s.rwMutex.Unlock()
return s.flush()
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | container/set/set.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/container/set/set.go#L50-L61 | go | train | // Returns a new set which is the union of s1 and s2. s1 and s2 are unmodified. | func Union(s1 Set, s2 Set) Set | // Returns a new set which is the union of s1 and s2. s1 and s2 are unmodified.
func Union(s1 Set, s2 Set) Set | {
if s1 == nil {
if s2 == nil {
return nil
}
return s2.Copy()
}
s3 := s1.Copy()
s3.Union(s2)
return s3
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | container/set/set.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/container/set/set.go#L65-L76 | go | train | // Returns a new set which is the intersect of s1 and s2. s1 and s2 are
// unmodified. | func Intersect(s1 Set, s2 Set) Set | // Returns a new set which is the intersect of s1 and s2. s1 and s2 are
// unmodified.
func Intersect(s1 Set, s2 Set) Set | {
if s1 == nil {
if s2 == nil {
return nil
}
return s2.New()
}
s3 := s1.Copy()
s3.Intersect(s2)
return s3
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | container/set/set.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/container/set/set.go#L80-L91 | go | train | // Returns a new set which is the difference between s1 and s2. s1 and s2 are
// unmodified. | func Subtract(s1 Set, s2 Set) Set | // Returns a new set which is the difference between s1 and s2. s1 and s2 are
// unmodified.
func Subtract(s1 Set, s2 Set) Set | {
if s1 == nil {
if s2 == nil {
return nil
}
return s2.New()
}
s3 := s1.Copy()
s3.Subtract(s2)
return s3
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | container/set/set.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/container/set/set.go#L94-L102 | go | train | // Returns a new Set pre-populated with the given items | func NewSet(items ...interface{}) Set | // Returns a new Set pre-populated with the given items
func NewSet(items ...interface{}) Set | {
res := setImpl{
data: make(map[interface{}]struct{}),
}
for _, item := range items {
res.Add(item)
}
return res
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | container/set/set.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/container/set/set.go#L105-L114 | go | train | // Returns a new Set pre-populated with the given items | func NewKeyedSet(keyf func(interface{}) interface{}, items ...interface{}) Set | // Returns a new Set pre-populated with the given items
func NewKeyedSet(keyf func(interface{}) interface{}, items ...interface{}) Set | {
res := keyedSetImpl{
data: make(map[interface{}]interface{}),
keyfunc: keyf,
}
for _, item := range items {
res.Add(item)
}
return res
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | container/set/set.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/container/set/set.go#L340-L346 | go | train | // Common functions between the two implementations, since go
// does not allow for any inheritance. | func equal(s Set, s2 Set) bool | // Common functions between the two implementations, since go
// does not allow for any inheritance.
func equal(s Set, s2 Set) bool | {
if s.Len() != s2.Len() {
return false
}
return s.IsSubset(s2)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L103-L110 | go | train | // This creates a new memcache RawBinaryClient. | func NewRawBinaryClient(shard int, channel io.ReadWriter) ClientShard | // This creates a new memcache RawBinaryClient.
func NewRawBinaryClient(shard int, channel io.ReadWriter) ClientShard | {
return &RawBinaryClient{
shard: shard,
channel: channel,
validState: true,
maxValueLength: defaultMaxValueLength,
}
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L113-L120 | go | train | // This creates a new memcache RawBinaryClient for use with np-large cluster. | func NewLargeRawBinaryClient(shard int, channel io.ReadWriter) ClientShard | // This creates a new memcache RawBinaryClient for use with np-large cluster.
func NewLargeRawBinaryClient(shard int, channel io.ReadWriter) ClientShard | {
return &RawBinaryClient{
shard: shard,
channel: channel,
validState: true,
maxValueLength: largeMaxValueLength,
}
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L134-L199 | go | train | // Sends a memcache request through the connection. NOTE: extras must be
// fix-sized values. | func (c *RawBinaryClient) sendRequest(
code opCode,
dataVersionId uint64, // aka CAS
key []byte, // may be nil
value []byte, // may be nil
extras ...interface{}) (err error) | // Sends a memcache request through the connection. NOTE: extras must be
// fix-sized values.
func (c *RawBinaryClient) sendRequest(
code opCode,
dataVersionId uint64, // aka CAS
key []byte, // may be nil
value []byte, // may be nil
extras ...interface{}) (err error) | {
if key != nil && len(key) > 255 {
return errors.New("Key too long")
}
if !c.validState {
// An error has occurred previously. It's not safe to continue sending.
return errors.New("Skipping due to previous error")
}
defer func() {
if err != nil {
c.validState = false
}
}()
extrasBuffer := new(bytes.Buffer)
for _, extra := range extras {
err := binary.Write(extrasBuffer, binary.BigEndian, extra)
if err != nil {
return errors.Wrap(err, "Failed to write extra")
}
}
// NOTE:
// - memcache only supports a single dataType (0x0)
// - vbucket id is not used by the library since vbucket related op
// codes are unsupported
hdr := header{
Magic: reqMagicByte,
OpCode: byte(code),
KeyLength: uint16(len(key)),
ExtrasLength: uint8(extrasBuffer.Len()),
TotalBodyLength: uint32(len(key) + len(value) + extrasBuffer.Len()),
DataVersionId: dataVersionId,
}
var msgBuffer = make([]byte, headerLength+hdr.TotalBodyLength)
hdr.Serialize(msgBuffer)
var offset uint32 = headerLength
offset += uint32(copy(msgBuffer[offset:], extrasBuffer.Bytes()))
if key != nil {
offset += uint32(copy(msgBuffer[offset:], key))
}
if value != nil {
offset += uint32(copy(msgBuffer[offset:], value))
}
if offset != headerLength+hdr.TotalBodyLength {
return errors.New("Failed to serialize message")
}
bytesWritten, err := c.channel.Write(msgBuffer)
if err != nil {
return errors.Wrap(err, "Failed to send msg")
}
if bytesWritten != int((hdr.TotalBodyLength)+headerLength) {
return errors.New("Failed to sent out message")
}
return nil
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L205-L308 | go | train | // Receive a memcache response from the connection. The status,
// dataVersionId (aka CAS), key and value are returned, while the extra
// values are stored in the arguments. NOTE: extras must be pointers to
// fix-sized values. | func (c *RawBinaryClient) receiveResponse(
expectedCode opCode,
extras ...interface{}) (
status ResponseStatus,
dataVersionId uint64,
key []byte, // is nil when key length is zero
value []byte, // is nil when the value length is zero
err error) | // Receive a memcache response from the connection. The status,
// dataVersionId (aka CAS), key and value are returned, while the extra
// values are stored in the arguments. NOTE: extras must be pointers to
// fix-sized values.
func (c *RawBinaryClient) receiveResponse(
expectedCode opCode,
extras ...interface{}) (
status ResponseStatus,
dataVersionId uint64,
key []byte, // is nil when key length is zero
value []byte, // is nil when the value length is zero
err error) | {
if !c.validState {
// An error has occurred previously. It's not safe to continue sending.
err = errors.New("Skipping due to previous error")
return
}
defer func() {
if err != nil {
c.validState = false
}
}()
// Process the header fields
hdr := header{}
var hdrBytes = make([]byte, headerLength)
hdrBytesRead, err := io.ReadFull(c.channel, hdrBytes)
if err != nil {
err = errors.Wrap(err, "Failed to read header")
return
}
if hdrBytesRead != headerLength {
err = errors.Newf("Failed to read header: got %d bytes, expected %d",
hdrBytesRead, headerLength)
return
}
hdr.Deserialize(hdrBytes)
if hdr.Magic != respMagicByte {
err = errors.Newf("Invalid response magic byte: %d", hdr.Magic)
return
}
if hdr.OpCode != byte(expectedCode) {
err = errors.Newf("Invalid response op code: %d", hdr.OpCode)
return
}
if hdr.DataType != 0 {
err = errors.Newf("Invalid data type: %d", hdr.DataType)
return
}
valueLength := int(hdr.TotalBodyLength)
valueLength -= (int(hdr.KeyLength) + int(hdr.ExtrasLength))
if valueLength < 0 {
err = errors.Newf("Invalid response header. Wrong payload size.")
return
}
status = ResponseStatus(hdr.VBucketIdOrStatus)
dataVersionId = hdr.DataVersionId
if hdr.ExtrasLength == 0 {
if status == StatusNoError && len(extras) != 0 {
err = errors.Newf("Expecting extras payload")
return
}
// the response has no extras
} else {
extrasBytes := make([]byte, hdr.ExtrasLength, hdr.ExtrasLength)
if _, err = io.ReadFull(c.channel, extrasBytes); err != nil {
err = errors.Wrap(err, "Failed to read extra")
return
}
extrasBuffer := bytes.NewBuffer(extrasBytes)
for _, extra := range extras {
err = binary.Read(extrasBuffer, binary.BigEndian, extra)
if err != nil {
err = errors.Wrap(err, "Failed to deserialize extra")
return
}
}
if extrasBuffer.Len() != 0 {
err = errors.Newf("Not all bytes are consumed by extras fields")
return
}
}
if hdr.KeyLength > 0 {
key = make([]byte, hdr.KeyLength, hdr.KeyLength)
if _, err = io.ReadFull(c.channel, key); err != nil {
err = errors.Wrap(err, "Failed to read key")
return
}
}
if valueLength > 0 {
value = make([]byte, valueLength, valueLength)
if _, err = io.ReadFull(c.channel, value); err != nil {
err = errors.Wrap(err, "Failed to read value")
return
}
}
return
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L335-L344 | go | train | // See Client interface for documentation. | func (c *RawBinaryClient) Get(key string) GetResponse | // See Client interface for documentation.
func (c *RawBinaryClient) Get(key string) GetResponse | {
c.mutex.Lock()
defer c.mutex.Unlock()
if resp := c.sendGetRequest(key); resp != nil {
return resp
}
return c.receiveGetResponse(key)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L361-L386 | go | train | // See Client interface for documentation. | func (c *RawBinaryClient) GetMulti(keys []string) map[string]GetResponse | // See Client interface for documentation.
func (c *RawBinaryClient) GetMulti(keys []string) map[string]GetResponse | {
if keys == nil {
return nil
}
responses := make(map[string]GetResponse)
cacheKeys := c.removeDuplicateKey(keys)
c.mutex.Lock()
defer c.mutex.Unlock()
for _, key := range cacheKeys {
if resp := c.sendGetRequest(key); resp != nil {
responses[key] = resp
}
}
for _, key := range cacheKeys {
if _, inMap := responses[key]; inMap { // error occurred while sending
continue
}
responses[key] = c.receiveGetResponse(key)
}
return responses
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L443-L456 | go | train | // Perform a mutation operation specified by the given code. | func (c *RawBinaryClient) mutate(code opCode, item *Item) MutateResponse | // Perform a mutation operation specified by the given code.
func (c *RawBinaryClient) mutate(code opCode, item *Item) MutateResponse | {
if item == nil {
return NewMutateErrorResponse("", errors.New("item is nil"))
}
c.mutex.Lock()
defer c.mutex.Unlock()
if resp := c.sendMutateRequest(code, item, true); resp != nil {
return resp
}
return c.receiveMutateResponse(code, item.Key)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L461-L500 | go | train | // Batch version of the mutate method. Note that the response entries
// ordering is undefined (i.e., may not match the input ordering)
// When DataVersionId is 0, zeroVersionIdCode is used instead of code. | func (c *RawBinaryClient) mutateMulti(
code opCode, zeroVersionIdCode opCode,
items []*Item) []MutateResponse | // Batch version of the mutate method. Note that the response entries
// ordering is undefined (i.e., may not match the input ordering)
// When DataVersionId is 0, zeroVersionIdCode is used instead of code.
func (c *RawBinaryClient) mutateMulti(
code opCode, zeroVersionIdCode opCode,
items []*Item) []MutateResponse | {
if items == nil {
return nil
}
responses := make([]MutateResponse, len(items), len(items))
// Short-circuit function to avoid locking.
if len(items) == 0 {
return responses
}
c.mutex.Lock()
defer c.mutex.Unlock()
var itemCode opCode
for i, item := range items {
itemCode = code
if item.DataVersionId == 0 {
itemCode = zeroVersionIdCode
}
responses[i] = c.sendMutateRequest(itemCode, item, true)
}
for i, item := range items {
if responses[i] != nil { // error occurred while sending
continue
}
itemCode = code
if item.DataVersionId == 0 {
itemCode = zeroVersionIdCode
}
responses[i] = c.receiveMutateResponse(itemCode, item.Key)
}
return responses
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L503-L505 | go | train | // See Client interface for documentation. | func (c *RawBinaryClient) Set(item *Item) MutateResponse | // See Client interface for documentation.
func (c *RawBinaryClient) Set(item *Item) MutateResponse | {
return c.mutate(opSet, item)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L508-L510 | go | train | // See Client interface for documentation. | func (c *RawBinaryClient) SetMulti(items []*Item) []MutateResponse | // See Client interface for documentation.
func (c *RawBinaryClient) SetMulti(items []*Item) []MutateResponse | {
return c.mutateMulti(opSet, opSet, items)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L520-L522 | go | train | // See Client interface for documentation. | func (c *RawBinaryClient) CasMulti(items []*Item) []MutateResponse | // See Client interface for documentation.
func (c *RawBinaryClient) CasMulti(items []*Item) []MutateResponse | {
return c.mutateMulti(opSet, opAdd, items)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L532-L534 | go | train | // See Client interface for documentation. | func (c *RawBinaryClient) Add(item *Item) MutateResponse | // See Client interface for documentation.
func (c *RawBinaryClient) Add(item *Item) MutateResponse | {
return c.mutate(opAdd, item)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L537-L539 | go | train | // See Client interface for documentation. | func (c *RawBinaryClient) AddMulti(items []*Item) []MutateResponse | // See Client interface for documentation.
func (c *RawBinaryClient) AddMulti(items []*Item) []MutateResponse | {
return c.mutateMulti(opAdd, opAdd, items)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L542-L555 | go | train | // See Client interface for documentation. | func (c *RawBinaryClient) Replace(item *Item) MutateResponse | // See Client interface for documentation.
func (c *RawBinaryClient) Replace(item *Item) MutateResponse | {
if item == nil {
return NewMutateErrorResponse("", errors.New("item is nil"))
}
c.mutex.Lock()
defer c.mutex.Unlock()
if resp := c.sendMutateRequest(opReplace, item, true); resp != nil {
return resp
}
return c.receiveMutateResponse(opReplace, item.Key)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L571-L580 | go | train | // See Client interface for documentation. | func (c *RawBinaryClient) Delete(key string) MutateResponse | // See Client interface for documentation.
func (c *RawBinaryClient) Delete(key string) MutateResponse | {
c.mutex.Lock()
defer c.mutex.Unlock()
if resp := c.sendDeleteRequest(key); resp != nil {
return resp
}
return c.receiveMutateResponse(opDelete, key)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L583-L605 | go | train | // See Client interface for documentation. | func (c *RawBinaryClient) DeleteMulti(keys []string) []MutateResponse | // See Client interface for documentation.
func (c *RawBinaryClient) DeleteMulti(keys []string) []MutateResponse | {
if keys == nil {
return nil
}
responses := make([]MutateResponse, len(keys), len(keys))
c.mutex.Lock()
defer c.mutex.Unlock()
for i, key := range keys {
responses[i] = c.sendDeleteRequest(key)
}
for i, key := range keys {
if responses[i] != nil { // error occurred while sending
continue
}
responses[i] = c.receiveMutateResponse(opDelete, key)
}
return responses
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L608-L622 | go | train | // See Client interface for documentation. | func (c *RawBinaryClient) Append(key string, value []byte) MutateResponse | // See Client interface for documentation.
func (c *RawBinaryClient) Append(key string, value []byte) MutateResponse | {
item := &Item{
Key: key,
Value: value,
}
c.mutex.Lock()
defer c.mutex.Unlock()
if resp := c.sendMutateRequest(opAppend, item, false); resp != nil {
return resp
}
return c.receiveMutateResponse(opAppend, item.Key)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L687-L701 | go | train | // See Client interface for documentation. | func (c *RawBinaryClient) Increment(
key string,
delta uint64,
initValue uint64,
expiration uint32) CountResponse | // See Client interface for documentation.
func (c *RawBinaryClient) Increment(
key string,
delta uint64,
initValue uint64,
expiration uint32) CountResponse | {
c.mutex.Lock()
defer c.mutex.Unlock()
resp := c.sendCountRequest(opIncrement, key, delta, initValue, expiration)
if resp != nil {
return resp
}
return c.receiveCountResponse(opIncrement, key)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L721-L757 | go | train | // See Client interface for documentation. | func (c *RawBinaryClient) Stat(statsKey string) StatResponse | // See Client interface for documentation.
func (c *RawBinaryClient) Stat(statsKey string) StatResponse | {
shardEntries := make(map[int](map[string]string))
entries := make(map[string]string)
shardEntries[c.ShardId()] = entries
c.mutex.Lock()
defer c.mutex.Unlock()
if !isValidKeyString(statsKey) {
return NewStatErrorResponse(
errors.Newf("Invalid key: %s", statsKey),
shardEntries)
}
err := c.sendRequest(opStat, 0, []byte(statsKey), nil)
if err != nil {
return NewStatErrorResponse(err, shardEntries)
}
for true {
status, _, key, value, err := c.receiveResponse(opStat)
if err != nil {
return NewStatErrorResponse(err, shardEntries)
}
if status != StatusNoError {
// In theory, this is a valid state, but treating this as valid
// complicates the code even more.
c.validState = false
return NewStatResponse(status, shardEntries)
}
if key == nil && value == nil { // the last entry
break
}
entries[string(key)] = string(value)
}
return NewStatResponse(StatusNoError, shardEntries)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L760-L778 | go | train | // See Client interface for documentation. | func (c *RawBinaryClient) Version() VersionResponse | // See Client interface for documentation.
func (c *RawBinaryClient) Version() VersionResponse | {
versions := make(map[int]string)
c.mutex.Lock()
defer c.mutex.Unlock()
err := c.sendRequest(opVersion, 0, nil, nil)
if err != nil {
return NewVersionErrorResponse(err, versions)
}
status, _, _, value, err := c.receiveResponse(opVersion)
if err != nil {
return NewVersionErrorResponse(err, versions)
}
versions[c.ShardId()] = string(value)
return NewVersionResponse(status, versions)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L800-L802 | go | train | // See Client interface for documentation. | func (c *RawBinaryClient) Flush(expiration uint32) Response | // See Client interface for documentation.
func (c *RawBinaryClient) Flush(expiration uint32) Response | {
return c.genericOp(opFlush, expiration)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/raw_binary_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L805-L807 | go | train | // See Client interface for documentation. | func (c *RawBinaryClient) Verbosity(verbosity uint32) Response | // See Client interface for documentation.
func (c *RawBinaryClient) Verbosity(verbosity uint32) Response | {
return c.genericOp(opVerbosity, verbosity)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | rate_limiter/rate_limiter.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/rate_limiter/rate_limiter.go#L147-L151 | go | train | // This returns the leaky bucket's maximum capacity. | func (l *rateLimiterImpl) MaxQuota() float64 | // This returns the leaky bucket's maximum capacity.
func (l *rateLimiterImpl) MaxQuota() float64 | {
l.mutex.Lock()
defer l.mutex.Unlock()
return l.maxQuota
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | rate_limiter/rate_limiter.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/rate_limiter/rate_limiter.go#L155-L173 | go | train | // This sets the leaky bucket's maximum capacity. The value must be
// non-negative. | func (l *rateLimiterImpl) SetMaxQuota(q float64) error | // This sets the leaky bucket's maximum capacity. The value must be
// non-negative.
func (l *rateLimiterImpl) SetMaxQuota(q float64) error | {
if q < 0 {
return errors.Newf("Max quota must be non-negative: %f", q)
}
l.mutex.Lock()
defer l.mutex.Unlock()
l.maxQuota = q
if l.quota > q {
l.quota = q
}
if l.maxQuota == 0 {
l.cond.Broadcast()
}
return nil
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | rate_limiter/rate_limiter.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/rate_limiter/rate_limiter.go#L176-L181 | go | train | // This returns the leaky bucket's fill rate. | func (l *rateLimiterImpl) QuotaPerSec() float64 | // This returns the leaky bucket's fill rate.
func (l *rateLimiterImpl) QuotaPerSec() float64 | {
l.mutex.Lock()
defer l.mutex.Unlock()
return l.quotaPerSec
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | rate_limiter/rate_limiter.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/rate_limiter/rate_limiter.go#L184-L195 | go | train | // This sets the leaky bucket's fill rate. The value must be non-negative. | func (l *rateLimiterImpl) SetQuotaPerSec(r float64) error | // This sets the leaky bucket's fill rate. The value must be non-negative.
func (l *rateLimiterImpl) SetQuotaPerSec(r float64) error | {
if r < 0 {
return errors.Newf("Quota per second must be non-negative: %f", r)
}
l.mutex.Lock()
defer l.mutex.Unlock()
l.quotaPerSec = r
return nil
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | rate_limiter/rate_limiter.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/rate_limiter/rate_limiter.go#L198-L202 | go | train | // This returns the current available quota. | func (l *rateLimiterImpl) Quota() float64 | // This returns the current available quota.
func (l *rateLimiterImpl) Quota() float64 | {
l.mutex.Lock()
defer l.mutex.Unlock()
return l.quota
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | rate_limiter/rate_limiter.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/rate_limiter/rate_limiter.go#L205-L209 | go | train | // Only used for testing. | func (l *rateLimiterImpl) setQuota(q float64) | // Only used for testing.
func (l *rateLimiterImpl) setQuota(q float64) | {
l.mutex.Lock()
defer l.mutex.Unlock()
l.quota = q
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | rate_limiter/rate_limiter.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/rate_limiter/rate_limiter.go#L217-L219 | go | train | // This blocks until the request amount of resources is acquired. This
// returns false if the request can be satisfied immediately. Otherwise, this
// returns true.
//
// NOTE: When maxQuota is zero, or when the rate limiter is stopped,
// this returns immediately. | func (l *rateLimiterImpl) Throttle(request float64) bool | // This blocks until the request amount of resources is acquired. This
// returns false if the request can be satisfied immediately. Otherwise, this
// returns true.
//
// NOTE: When maxQuota is zero, or when the rate limiter is stopped,
// this returns immediately.
func (l *rateLimiterImpl) Throttle(request float64) bool | {
return l.throttle(request, false /* tryOnce */)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | rate_limiter/rate_limiter.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/rate_limiter/rate_limiter.go#L262-L276 | go | train | // Stop the rate limiter. | func (l *rateLimiterImpl) Stop() | // Stop the rate limiter.
func (l *rateLimiterImpl) Stop() | {
l.mutex.Lock()
defer l.mutex.Unlock()
if l.stopped {
return
}
l.stopped = true
close(l.stopChan)
l.ticker.Stop()
l.cond.Broadcast()
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | database/binlog/temporal_fields.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/binlog/temporal_fields.go#L34-L42 | go | train | // This contains field descriptors for temporal types as defined by
// sql/field.h. In particular:
//
// Field (abstract)
// |
// ...
// | +--Field_year
// ...
// |
// +--Field_temporal (abstract)
// +--Field_time_common (abstract)
// | +--Field_time
// | +--Field_timef
// |
// +--Field_temporal_with_date (abstract)
// +--Field_newdate
// +--Field_temporal_with_date_and_time (abstract)
// +--Field_timestamp
// +--Field_datetime
// +--Field_temporal_with_date_and_timef (abstract)
// +--Field_timestampf
// +--Field_datetimef
// This returns a field descriptor for FieldType_YEAR (i.e., Field_year) | func NewYearFieldDescriptor(nullable NullableColumn) FieldDescriptor | // This contains field descriptors for temporal types as defined by
// sql/field.h. In particular:
//
// Field (abstract)
// |
// ...
// | +--Field_year
// ...
// |
// +--Field_temporal (abstract)
// +--Field_time_common (abstract)
// | +--Field_time
// | +--Field_timef
// |
// +--Field_temporal_with_date (abstract)
// +--Field_newdate
// +--Field_temporal_with_date_and_time (abstract)
// +--Field_timestamp
// +--Field_datetime
// +--Field_temporal_with_date_and_timef (abstract)
// +--Field_timestampf
// +--Field_datetimef
// This returns a field descriptor for FieldType_YEAR (i.e., Field_year)
func NewYearFieldDescriptor(nullable NullableColumn) FieldDescriptor | {
return newFixedLengthFieldDescriptor(
mysql_proto.FieldType_YEAR,
nullable,
1,
func(b []byte) interface{} {
return time.Date(int(b[0])+1900, 0, 0, 0, 0, 0, 0, time.UTC)
})
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | database/binlog/temporal_fields.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/binlog/temporal_fields.go#L46-L54 | go | train | // This returns a fields descriptor for FieldType_TIMESTAMP
// (i.e., Field_timestamp) | func NewTimestampFieldDescriptor(nullable NullableColumn) FieldDescriptor | // This returns a fields descriptor for FieldType_TIMESTAMP
// (i.e., Field_timestamp)
func NewTimestampFieldDescriptor(nullable NullableColumn) FieldDescriptor | {
return newFixedLengthFieldDescriptor(
mysql_proto.FieldType_TIMESTAMP,
nullable,
4,
func(b []byte) interface{} {
return time.Unix(int64(LittleEndian.Uint32(b)), 0).UTC()
})
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | database/binlog/temporal_fields.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/binlog/temporal_fields.go#L59-L78 | go | train | // This returns a fields descriptor for FieldType_DATETIME
// (i.e., Field_datetime). See number_to_datetime (in sql-common/my_time.c)
// for encoding detail. | func NewDateTimeFieldDescriptor(nullable NullableColumn) FieldDescriptor | // This returns a fields descriptor for FieldType_DATETIME
// (i.e., Field_datetime). See number_to_datetime (in sql-common/my_time.c)
// for encoding detail.
func NewDateTimeFieldDescriptor(nullable NullableColumn) FieldDescriptor | {
return newFixedLengthFieldDescriptor(
mysql_proto.FieldType_DATETIME,
nullable,
8,
func(b []byte) interface{} {
val := LittleEndian.Uint64(b)
d := val / 1000000
t := val % 1000000
return time.Date(
int(d/10000), // year
time.Month((d%10000)/100), // month
int(d%100), // day
int(t/10000), // hour
int((t%10000)/100), // minute
int(t%100), // second
0, // nanosecond
time.UTC)
})
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | database/binlog/temporal_fields.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/binlog/temporal_fields.go#L158-L175 | go | train | // This returns a field descriptor for FieldType_TIMESTAMP2
// (i.e., Field_timestampf). See my_timestamp_from_binary (in
// sql-common/my_time.c) for encoding detail. | func NewTimestamp2FieldDescriptor(nullable NullableColumn, metadata []byte) (
fd FieldDescriptor,
remaining []byte,
err error) | // This returns a field descriptor for FieldType_TIMESTAMP2
// (i.e., Field_timestampf). See my_timestamp_from_binary (in
// sql-common/my_time.c) for encoding detail.
func NewTimestamp2FieldDescriptor(nullable NullableColumn, metadata []byte) (
fd FieldDescriptor,
remaining []byte,
err error) | {
t := ×tamp2FieldDescriptor{}
remaining, err = t.init(
mysql_proto.FieldType_TIMESTAMP2,
nullable,
4,
metadata)
if err != nil {
return nil, nil, err
}
return t, remaining, nil
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | database/binlog/temporal_fields.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/binlog/temporal_fields.go#L202-L220 | go | train | // This returns a field descriptor for FieldType_DATETIME2
// (i.e., Field_datetimef). See TIME_from_longlong_datetime_packed (
// in sql-common/my_time.c) for encoding detail. | func NewDateTime2FieldDescriptor(nullable NullableColumn, metadata []byte) (
fd FieldDescriptor,
remaining []byte,
err error) | // This returns a field descriptor for FieldType_DATETIME2
// (i.e., Field_datetimef). See TIME_from_longlong_datetime_packed (
// in sql-common/my_time.c) for encoding detail.
func NewDateTime2FieldDescriptor(nullable NullableColumn, metadata []byte) (
fd FieldDescriptor,
remaining []byte,
err error) | {
d := &datetime2FieldDescriptor{}
remaining, err = d.init(
mysql_proto.FieldType_DATETIME2,
nullable,
5,
metadata)
if err != nil {
return nil, nil, err
}
return d, remaining, nil
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | io2/reader_to_writer_adapter.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/io2/reader_to_writer_adapter.go#L32-L42 | go | train | // This makes a new ReaderToWriterAdapter
// it requires a factory to generate the writer-to-be-wrapped
// The reason is that the writer will require another "downstream" writer
// to be bound with. Each type of writer (eg zlib.NewWriter) may have
// a slightly different way of being bound with a downstream writer
// so here, the user must provide a factory function into this
// constructor and then the constructor will be invoked with an
// implementation-defined downstream writer, which will allow the writer
// to act as a reader from the outside | func NewReaderToWriterAdapter(writerFactory func(io.Writer) (io.Writer, error),
upstream io.Reader) (io.ReadCloser, error) | // This makes a new ReaderToWriterAdapter
// it requires a factory to generate the writer-to-be-wrapped
// The reason is that the writer will require another "downstream" writer
// to be bound with. Each type of writer (eg zlib.NewWriter) may have
// a slightly different way of being bound with a downstream writer
// so here, the user must provide a factory function into this
// constructor and then the constructor will be invoked with an
// implementation-defined downstream writer, which will allow the writer
// to act as a reader from the outside
func NewReaderToWriterAdapter(writerFactory func(io.Writer) (io.Writer, error),
upstream io.Reader) (io.ReadCloser, error) | {
retval := ReaderToWriterAdapter{
writer: nil,
upstream: upstream,
readBuffer: make([]byte, 65536),
}
var err error
retval.writer, err = writerFactory(&retval.writeBuffer)
return &retval, err
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | io2/reader_to_writer_adapter.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/io2/reader_to_writer_adapter.go#L67-L79 | go | train | // writes, preferably to the userBuffer but then optionally to the remainder | func (sbself *splitBufferedWriter) Write(data []byte) (int, error) | // writes, preferably to the userBuffer but then optionally to the remainder
func (sbself *splitBufferedWriter) Write(data []byte) (int, error) | {
toCopy := len(sbself.userBuffer) - sbself.userBufferCount
if toCopy > len(data) {
toCopy = len(data)
}
copy(sbself.userBuffer[sbself.userBufferCount:sbself.userBufferCount+toCopy], data[:toCopy])
sbself.userBufferCount += toCopy
if toCopy < len(data) { // we need to overflow to remainder
count, err := sbself.remainder.Write(data[toCopy:])
return count + toCopy, err
}
return toCopy, nil
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | io2/reader_to_writer_adapter.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/io2/reader_to_writer_adapter.go#L88-L100 | go | train | // removes the user buffer from the splitBufferedWriter
// This makes sure that if the user buffer is only somewhat full, no data remains in the remainder
// This preserves the remainder buffer, since that will be consumed later | func (sbself *splitBufferedWriter) RemoveUserBuffer() (amountReturned int, err error) | // removes the user buffer from the splitBufferedWriter
// This makes sure that if the user buffer is only somewhat full, no data remains in the remainder
// This preserves the remainder buffer, since that will be consumed later
func (sbself *splitBufferedWriter) RemoveUserBuffer() (amountReturned int, err error) | {
if len(sbself.userBuffer) > sbself.userBufferCount {
if len(sbself.remainder.Bytes()) != 0 {
err = errors.New("remainder must be clear if userBuffer isn't full")
panic(err)
}
}
amountReturned = sbself.userBufferCount
sbself.userBuffer = nil
sbself.userBufferCount = 0
return
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | io2/reader_to_writer_adapter.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/io2/reader_to_writer_adapter.go#L104-L110 | go | train | // installs a user buffer into the splitBufferedWriter, resetting
// the remainder and original buffer | func (sbself *splitBufferedWriter) InstallNewUserBufferAndResetRemainder(
data []byte) | // installs a user buffer into the splitBufferedWriter, resetting
// the remainder and original buffer
func (sbself *splitBufferedWriter) InstallNewUserBufferAndResetRemainder(
data []byte) | {
sbself.remainder.Reset()
sbself.userBuffer = data
sbself.userBufferCount = 0
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | io2/reader_to_writer_adapter.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/io2/reader_to_writer_adapter.go#L117-L177 | go | train | // implements the Read interface by wrapping the Writer with some buffers | func (rwaself *ReaderToWriterAdapter) Read(data []byte) (int, error) | // implements the Read interface by wrapping the Writer with some buffers
func (rwaself *ReaderToWriterAdapter) Read(data []byte) (int, error) | {
lenToCopy := len(rwaself.writeBuffer.Bytes()) - rwaself.offset
if lenToCopy > 0 {
// if we have leftover data from a previous call, we can return that only
if lenToCopy > len(data) {
lenToCopy = len(data)
}
copy(data[:lenToCopy],
rwaself.writeBuffer.Bytes()[rwaself.offset:rwaself.offset+lenToCopy])
rwaself.offset += lenToCopy
// only return deferred errors if we have consumed the entire remainder
if rwaself.offset < len(rwaself.writeBuffer.Bytes()) {
return lenToCopy, nil // if still remainder left, return nil
} else {
err := rwaself.deferredErr
rwaself.deferredErr = nil
return lenToCopy, err
}
}
rwaself.offset = 0
// if we have no data from previous runs, lets install the buffer and copy to the writer
rwaself.writeBuffer.InstallNewUserBufferAndResetRemainder(data)
for {
// read from the upstream
readBufferLenValid, err := rwaself.upstream.Read(rwaself.readBuffer)
var writeErr error
var closeErr error
if readBufferLenValid > 0 {
// copy data to the writer
_, writeErr = rwaself.writer.Write(rwaself.readBuffer[:readBufferLenValid])
}
if err == io.EOF && !rwaself.closedWriter {
rwaself.closedWriter = true
if writeCloser, ok := rwaself.writer.(io.WriteCloser); ok {
closeErr = writeCloser.Close()
}
}
if err == nil && (writeErr != nil || closeErr != nil) {
_ = rwaself.drain() // if there was an error with the writer, drain the upstream
}
if (err == nil || err == io.EOF) && writeErr != nil {
err = writeErr
}
if (err == nil || err == io.EOF) && closeErr != nil {
err = closeErr
}
if rwaself.writeBuffer.GetAmountCopiedToUser() > 0 || err != nil {
if rwaself.offset < len(rwaself.writeBuffer.Bytes()) {
rwaself.deferredErr = err
err = nil
}
amountCopiedToUser, err2 := rwaself.writeBuffer.RemoveUserBuffer()
if err == nil && err2 != nil {
err = err2 // this is an internal assertion/check. it should not trip
} // possibly change to a panic?
return amountCopiedToUser, err
}
}
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | io2/reader_to_writer_adapter.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/io2/reader_to_writer_adapter.go#L180-L200 | go | train | // interrupt the read by closing all resources | func (rwaself *ReaderToWriterAdapter) Close() error | // interrupt the read by closing all resources
func (rwaself *ReaderToWriterAdapter) Close() error | {
var wCloseErr error
var rCloseErr error
if writeCloser, ok := rwaself.writer.(io.WriteCloser); ok {
if !rwaself.closedWriter {
wCloseErr = writeCloser.Close()
}
}
if readCloser, ok := rwaself.upstream.(io.ReadCloser); ok {
rCloseErr = readCloser.Close()
} else {
rCloseErr = rwaself.drain()
}
if rCloseErr != nil && rCloseErr != io.EOF {
return rCloseErr
}
if wCloseErr != nil && wCloseErr != io.EOF {
return wCloseErr
}
return nil
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | database/binlog/log_file_event_reader.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/binlog/log_file_event_reader.go#L58-L73 | go | train | // This returns an EventReader which read events from a single (bin / relay)
// log file, with appropriate parser applied on each event. If no parser is
// available for the event, or if an error occurs during parsing, then the
// reader will return the original event along with the error. NOTE: this
// reader is responsible for checking the log file magic marker, the binlog
// format version and all format description events within the stream. It is
// also responsible for setting the checksum size for non-FDE events. | func NewLogFileV4EventReader(
src io.Reader,
srcName string,
parsers V4EventParserMap,
logger Logger) EventReader | // This returns an EventReader which read events from a single (bin / relay)
// log file, with appropriate parser applied on each event. If no parser is
// available for the event, or if an error occurs during parsing, then the
// reader will return the original event along with the error. NOTE: this
// reader is responsible for checking the log file magic marker, the binlog
// format version and all format description events within the stream. It is
// also responsible for setting the checksum size for non-FDE events.
func NewLogFileV4EventReader(
src io.Reader,
srcName string,
parsers V4EventParserMap,
logger Logger) EventReader | {
rawReader := NewRawV4EventReader(src, srcName)
return &logFileV4EventReader{
reader: NewParsedV4EventReader(rawReader, parsers),
parsers: parsers,
passedMagicBytesCheck: false,
passedLogFormatVersionCheck: false,
logger: logger,
}
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | net2/http2/gzip.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/net2/http2/gzip.go#L19-L22 | go | train | // compressionLevel - one of the compression levels in the gzip package. | func NewGzipResponseWriter(writer http.ResponseWriter, compressionLevel int) gzipResponseWriter | // compressionLevel - one of the compression levels in the gzip package.
func NewGzipResponseWriter(writer http.ResponseWriter, compressionLevel int) gzipResponseWriter | {
gzWriter, _ := gzip.NewWriterLevel(writer, compressionLevel)
return gzipResponseWriter{ResponseWriter: writer, gzWriter: gzWriter}
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | sys/filelock/filelock.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sys/filelock/filelock.go#L70-L72 | go | train | // Non blocking way to try to acquire a shared lock. | func (f *FileLock) TryRLock() error | // Non blocking way to try to acquire a shared lock.
func (f *FileLock) TryRLock() error | {
return f.performLock(syscall.LOCK_SH | syscall.LOCK_NB)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | sys/filelock/filelock.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sys/filelock/filelock.go#L80-L82 | go | train | // Non blocking way to try to acquire an exclusive lock. | func (f *FileLock) TryLock() error | // Non blocking way to try to acquire an exclusive lock.
func (f *FileLock) TryLock() error | {
return f.performLock(syscall.LOCK_EX | syscall.LOCK_NB)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | sys/filelock/filelock.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sys/filelock/filelock.go#L116-L121 | go | train | // Returns whether the error returned by TryLock/TryRLock is the result of
// the lock already being held by another process. | func IsHeldElsewhere(err error) bool | // Returns whether the error returned by TryLock/TryRLock is the result of
// the lock already being held by another process.
func IsHeldElsewhere(err error) bool | {
if errno, ok := err.(syscall.Errno); ok {
return errno == syscall.EWOULDBLOCK
}
return false
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | database/sqlbuilder/column.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqlbuilder/column.go#L99-L107 | go | train | // Representation of VARBINARY/BLOB columns
// This function will panic if name is not valid | func BytesColumn(name string, nullable NullableColumn) NonAliasColumn | // Representation of VARBINARY/BLOB columns
// This function will panic if name is not valid
func BytesColumn(name string, nullable NullableColumn) NonAliasColumn | {
if !validIdentifierName(name) {
panic("Invalid column name in bytes column")
}
bc := &bytesColumn{}
bc.name = name
bc.nullable = nullable
return bc
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | database/sqlbuilder/column.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqlbuilder/column.go#L118-L131 | go | train | // Representation of VARCHAR/TEXT columns
// This function will panic if name is not valid | func StrColumn(
name string,
charset Charset,
collation Collation,
nullable NullableColumn) NonAliasColumn | // Representation of VARCHAR/TEXT columns
// This function will panic if name is not valid
func StrColumn(
name string,
charset Charset,
collation Collation,
nullable NullableColumn) NonAliasColumn | {
if !validIdentifierName(name) {
panic("Invalid column name in str column")
}
sc := &stringColumn{charset: charset, collation: collation}
sc.name = name
sc.nullable = nullable
return sc
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | database/sqlbuilder/column.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqlbuilder/column.go#L140-L148 | go | train | // Representation of DateTime columns
// This function will panic if name is not valid | func DateTimeColumn(name string, nullable NullableColumn) NonAliasColumn | // Representation of DateTime columns
// This function will panic if name is not valid
func DateTimeColumn(name string, nullable NullableColumn) NonAliasColumn | {
if !validIdentifierName(name) {
panic("Invalid column name in datetime column")
}
dc := &dateTimeColumn{}
dc.name = name
dc.nullable = nullable
return dc
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | database/sqlbuilder/column.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqlbuilder/column.go#L157-L165 | go | train | // Representation of any integer column
// This function will panic if name is not valid | func IntColumn(name string, nullable NullableColumn) NonAliasColumn | // Representation of any integer column
// This function will panic if name is not valid
func IntColumn(name string, nullable NullableColumn) NonAliasColumn | {
if !validIdentifierName(name) {
panic("Invalid column name in int column")
}
ic := &integerColumn{}
ic.name = name
ic.nullable = nullable
return ic
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | database/sqlbuilder/column.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqlbuilder/column.go#L174-L182 | go | train | // Representation of any double column
// This function will panic if name is not valid | func DoubleColumn(name string, nullable NullableColumn) NonAliasColumn | // Representation of any double column
// This function will panic if name is not valid
func DoubleColumn(name string, nullable NullableColumn) NonAliasColumn | {
if !validIdentifierName(name) {
panic("Invalid column name in int column")
}
ic := &doubleColumn{}
ic.name = name
ic.nullable = nullable
return ic
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | database/sqlbuilder/column.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqlbuilder/column.go#L194-L202 | go | train | // Representation of TINYINT used as a bool
// This function will panic if name is not valid | func BoolColumn(name string, nullable NullableColumn) NonAliasColumn | // Representation of TINYINT used as a bool
// This function will panic if name is not valid
func BoolColumn(name string, nullable NullableColumn) NonAliasColumn | {
if !validIdentifierName(name) {
panic("Invalid column name in bool column")
}
bc := &booleanColumn{}
bc.name = name
bc.nullable = nullable
return bc
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | database/sqlbuilder/column.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqlbuilder/column.go#L249-L254 | go | train | // Representation of aliased clauses (expression AS name) | func Alias(name string, c Expression) Column | // Representation of aliased clauses (expression AS name)
func Alias(name string, c Expression) Column | {
ac := &aliasColumn{}
ac.name = name
ac.expression = c
return ac
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | resource_pool/managed_handle.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/resource_pool/managed_handle.go#L46-L61 | go | train | // This creates a managed handle wrapper. | func NewManagedHandle(
resourceLocation string,
handle interface{},
pool ResourcePool,
options Options) ManagedHandle | // This creates a managed handle wrapper.
func NewManagedHandle(
resourceLocation string,
handle interface{},
pool ResourcePool,
options Options) ManagedHandle | {
h := &managedHandleImpl{
location: resourceLocation,
handle: handle,
pool: pool,
options: options,
}
atomic.StoreInt32(&h.isActive, 1)
return h
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | resource_pool/managed_handle.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/resource_pool/managed_handle.go#L69-L74 | go | train | // See ManagedHandle for documentation. | func (c *managedHandleImpl) Handle() (interface{}, error) | // See ManagedHandle for documentation.
func (c *managedHandleImpl) Handle() (interface{}, error) | {
if atomic.LoadInt32(&c.isActive) == 0 {
return c.handle, errors.New("Resource handle is no longer valid")
}
return c.handle, nil
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | resource_pool/managed_handle.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/resource_pool/managed_handle.go#L82-L87 | go | train | // See ManagedHandle for documentation. | func (c *managedHandleImpl) ReleaseUnderlyingHandle() interface{} | // See ManagedHandle for documentation.
func (c *managedHandleImpl) ReleaseUnderlyingHandle() interface{} | {
if atomic.CompareAndSwapInt32(&c.isActive, 1, 0) {
return c.handle
}
return nil
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/static_shard_manager.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/static_shard_manager.go#L22-L43 | go | train | // This creates a StaticShardManager, which returns connections from a static
// list of memcache shards. | func NewStaticShardManager(
serverAddrs []string,
shardFunc func(key string, numShard int) (shard int),
options net2.ConnectionOptions) ShardManager | // This creates a StaticShardManager, which returns connections from a static
// list of memcache shards.
func NewStaticShardManager(
serverAddrs []string,
shardFunc func(key string, numShard int) (shard int),
options net2.ConnectionOptions) ShardManager | {
manager := &StaticShardManager{}
manager.Init(
shardFunc,
func(err error) { log.Print(err) },
log.Print,
options)
shardStates := make([]ShardState, len(serverAddrs), len(serverAddrs))
for i, addr := range serverAddrs {
shardStates[i].Address = addr
shardStates[i].State = ActiveServer
}
manager.UpdateShardStates(shardStates)
return manager
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | bufio2/look_ahead_buffer.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/bufio2/look_ahead_buffer.go#L24-L26 | go | train | // NewLookAheadBuffer returns a new LookAheadBuffer whose raw buffer has EXACTLY
// the specified size. | func NewLookAheadBuffer(src io.Reader, bufferSize int) *LookAheadBuffer | // NewLookAheadBuffer returns a new LookAheadBuffer whose raw buffer has EXACTLY
// the specified size.
func NewLookAheadBuffer(src io.Reader, bufferSize int) *LookAheadBuffer | {
return NewLookAheadBufferUsing(src, make([]byte, bufferSize, bufferSize))
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | bufio2/look_ahead_buffer.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/bufio2/look_ahead_buffer.go#L31-L37 | go | train | // NewLookAheadBufferUsing returns a new LookAheadBuffer which uses the
// provided buffer as its raw buffer. This allows buffer reuse, which reduces
// unnecessary memory allocation. | func NewLookAheadBufferUsing(src io.Reader, rawBuffer []byte) *LookAheadBuffer | // NewLookAheadBufferUsing returns a new LookAheadBuffer which uses the
// provided buffer as its raw buffer. This allows buffer reuse, which reduces
// unnecessary memory allocation.
func NewLookAheadBufferUsing(src io.Reader, rawBuffer []byte) *LookAheadBuffer | {
return &LookAheadBuffer{
src: src,
buffer: rawBuffer,
bytesBuffered: 0,
}
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | bufio2/look_ahead_buffer.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/bufio2/look_ahead_buffer.go#L61-L95 | go | train | // Peek returns a slice of the look ahead buffer which holds numBytes
// number of bytes. If the look ahead buffer does not already hold enough
// bytes, it will read from the underlying reader to populate the rest.
// NOTE: the returned slice is not a copy of the raw buffer. | func (b *LookAheadBuffer) Peek(numBytes int) ([]byte, error) | // Peek returns a slice of the look ahead buffer which holds numBytes
// number of bytes. If the look ahead buffer does not already hold enough
// bytes, it will read from the underlying reader to populate the rest.
// NOTE: the returned slice is not a copy of the raw buffer.
func (b *LookAheadBuffer) Peek(numBytes int) ([]byte, error) | {
if numBytes < 0 {
return nil, errors.New("Cannot fill negative numBytes")
}
if numBytes > len(b.buffer) {
return nil, errors.Newf(
"Buffer full (buffer size: %d n: %d)",
len(b.buffer),
numBytes)
}
var err error
var numRead int
if b.bytesBuffered < numBytes {
numRead, err = io.ReadAtLeast(
b.src,
b.buffer[b.bytesBuffered:],
numBytes-b.bytesBuffered)
if err != nil {
if err == io.ErrUnexpectedEOF {
// ErrUnexpectedEOF is a terrible error only returned by
// ReadAtLeast. Return EOF (i.e., the original error) instead
// ErrUnexpectedEOF since no one ever checks for this.
err = io.EOF
}
}
}
b.bytesBuffered += numRead
if numBytes > b.bytesBuffered {
numBytes = b.bytesBuffered
}
return b.buffer[:numBytes], err
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | bufio2/look_ahead_buffer.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/bufio2/look_ahead_buffer.go#L101-L103 | go | train | // PeekAll returns the entire look ahead buffer with all bytes populated.
// If the look ahead buffer does not already hold enough bytes, it will read
// from the underlying reader to populate the rest. NOTE: the returned slice
// is not a copy of the raw buffer. | func (b *LookAheadBuffer) PeekAll() ([]byte, error) | // PeekAll returns the entire look ahead buffer with all bytes populated.
// If the look ahead buffer does not already hold enough bytes, it will read
// from the underlying reader to populate the rest. NOTE: the returned slice
// is not a copy of the raw buffer.
func (b *LookAheadBuffer) PeekAll() ([]byte, error) | {
return b.Peek(len(b.buffer))
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | bufio2/look_ahead_buffer.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/bufio2/look_ahead_buffer.go#L109-L123 | go | train | // Consume drops the first numBytes number of populated bytes from the look
// ahead buffer. NOTE: This is an O(n) operation since it requires shifting
// the remaining bytes to the beginning of the buffer. Avoid consuming the
// buffer byte by byte. | func (b *LookAheadBuffer) Consume(numBytes int) error | // Consume drops the first numBytes number of populated bytes from the look
// ahead buffer. NOTE: This is an O(n) operation since it requires shifting
// the remaining bytes to the beginning of the buffer. Avoid consuming the
// buffer byte by byte.
func (b *LookAheadBuffer) Consume(numBytes int) error | {
if numBytes == 0 {
return nil
}
if numBytes < 0 {
return errors.New("Cannot drop negative numBytes")
}
if b.bytesBuffered < numBytes {
return errors.New("Consuming more bytes than bytes in buffer.")
}
copy(b.buffer, b.buffer[numBytes:b.bytesBuffered])
b.bytesBuffered -= numBytes
return nil
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | bufio2/look_ahead_buffer.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/bufio2/look_ahead_buffer.go#L126-L131 | go | train | // ConsumeAll drops all populated bytes from the look ahead buffer. | func (b *LookAheadBuffer) ConsumeAll() | // ConsumeAll drops all populated bytes from the look ahead buffer.
func (b *LookAheadBuffer) ConsumeAll() | {
err := b.Consume(b.bytesBuffered)
if err != nil { // This should never happen
panic(err)
}
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | database/binlog/query_event.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/binlog/query_event.go#L152-L158 | go | train | // IsModeEnabled returns true iff sql mode status is set and the mode bit is
// set. | func (e *QueryEvent) IsModeEnabled(mode mysql_proto.SqlMode_BitPosition) bool | // IsModeEnabled returns true iff sql mode status is set and the mode bit is
// set.
func (e *QueryEvent) IsModeEnabled(mode mysql_proto.SqlMode_BitPosition) bool | {
if e.sqlMode == nil {
return false
}
return (*e.sqlMode & (uint64(1) << uint(mode))) != 0
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | database/binlog/query_event.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/binlog/query_event.go#L259-L302 | go | train | // QueryEventParser's Parse processes a raw query event into a QueryEvent. | func (p *QueryEventParser) Parse(raw *RawV4Event) (Event, error) | // QueryEventParser's Parse processes a raw query event into a QueryEvent.
func (p *QueryEventParser) Parse(raw *RawV4Event) (Event, error) | {
query := &QueryEvent{
Event: raw,
}
type fixedBodyStruct struct {
ThreadId uint32
Duration uint32
DatabaseNameLength uint8
ErrorCode uint16
StatusLength uint16
}
fixed := fixedBodyStruct{}
_, err := readLittleEndian(raw.FixedLengthData(), &fixed)
if err != nil {
return raw, errors.Wrap(err, "Failed to read fixed body")
}
query.threadId = fixed.ThreadId
query.duration = fixed.Duration
query.errorCode = mysql_proto.ErrorCode_Type(fixed.ErrorCode)
data := raw.VariableLengthData()
dbNameEnd := int(fixed.StatusLength) + int(fixed.DatabaseNameLength)
if dbNameEnd+1 > len(data) {
return raw, errors.Newf("Invalid message length")
}
query.statusBytes = data[:fixed.StatusLength]
query.databaseName = data[fixed.StatusLength:dbNameEnd]
query.query = data[dbNameEnd+1:]
err = p.parseStatus(query)
if err != nil {
return raw, err
}
return query, nil
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | database/binlog/rotate_event.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/binlog/rotate_event.go#L57-L69 | go | train | // RotateEventParser's Parse processes a raw rotate event into a RotateEvent. | func (p *RotateEventParser) Parse(raw *RawV4Event) (Event, error) | // RotateEventParser's Parse processes a raw rotate event into a RotateEvent.
func (p *RotateEventParser) Parse(raw *RawV4Event) (Event, error) | {
rotate := &RotateEvent{
Event: raw,
newLogName: raw.VariableLengthData(),
}
_, err := readLittleEndian(raw.FixedLengthData(), &rotate.newPosition)
if err != nil {
return raw, errors.Wrap(err, "Failed to read new log position")
}
return rotate, nil
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | database/binlog/format_description_event.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/binlog/format_description_event.go#L73-L77 | go | train | // FixedLengthDataSizeForType returns the size of fixed length data for each
// event type. | func (e *FormatDescriptionEvent) FixedLengthDataSizeForType(
eventType mysql_proto.LogEventType_Type) int | // FixedLengthDataSizeForType returns the size of fixed length data for each
// event type.
func (e *FormatDescriptionEvent) FixedLengthDataSizeForType(
eventType mysql_proto.LogEventType_Type) int | {
return e.fixedLengthSizes[eventType]
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | database/binlog/format_description_event.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/binlog/format_description_event.go#L116-L182 | go | train | // FormatDecriptionEventParser's Parse processes a raw FDE event into a
// FormatDescriptionEvent. | func (p *FormatDescriptionEventParser) Parse(raw *RawV4Event) (Event, error) | // FormatDecriptionEventParser's Parse processes a raw FDE event into a
// FormatDescriptionEvent.
func (p *FormatDescriptionEventParser) Parse(raw *RawV4Event) (Event, error) | {
fde := &FormatDescriptionEvent{
Event: raw,
fixedLengthSizes: make(map[mysql_proto.LogEventType_Type]int),
}
data := raw.VariableLengthData()
data, err := readLittleEndian(data, &fde.binlogVersion)
if err != nil {
return raw, errors.Wrap(err, "Failed to read binlog version")
}
serverVersion, data, err := readSlice(data, 50)
if err != nil {
return raw, errors.Wrap(err, "Failed to read server version")
}
if idx := bytes.IndexByte(serverVersion, byte(0)); idx > -1 {
serverVersion = serverVersion[:idx]
}
fde.serverVersion = serverVersion
data, err = readLittleEndian(data, &fde.createdTimestamp)
if err != nil {
return raw, errors.Wrap(err, "Failed to read created timestamp")
}
var totalHeaderSize uint8
data, err = readLittleEndian(data, &totalHeaderSize)
if err != nil {
return raw, errors.Wrap(err, "Failed to read total header size")
}
fde.extraHeadersSize = int(totalHeaderSize) - sizeOfBasicV4EventHeader
numEvents := len(mysql_proto.LogEventType_Type_value)
hasChecksum := true
if len(data) == 27 { // mysql 5.5(.37)
numEvents = 28
hasChecksum = false
} else if len(data) == 40 { // mysql 5.6(.17)
// This is a relay log where the master is 5.5 and slave is 5.6
if data[int(mysql_proto.LogEventType_WRITE_ROWS_EVENT)-1] == 0 {
numEvents = 28
}
} else {
return raw, errors.Newf(
"Unable to parse FDE for mysql variant: %s",
fde.serverVersion)
}
// unknown event's fixed length is implicit.
fde.fixedLengthSizes[mysql_proto.LogEventType_UNKNOWN_EVENT] = 0
for i := 1; i < numEvents; i++ {
fde.fixedLengthSizes[mysql_proto.LogEventType_Type(i)] = int(data[i-1])
}
if hasChecksum {
fde.checksumAlgorithm = mysql_proto.ChecksumAlgorithm_Type(
data[len(data)-5])
raw.SetChecksumSize(4)
}
return fde, nil
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | lockstore/store.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/lockstore/store.go#L91-L113 | go | train | // New creates a new LockStore given the options | func New(options LockStoreOptions) LockStore | // New creates a new LockStore given the options
func New(options LockStoreOptions) LockStore | {
testTryLockCallback := options.testTryLockCallback
if testTryLockCallback == nil {
testTryLockCallback = func() {}
}
lock := _LockStoreImp{
granularity: options.Granularity,
testTryLockCallback: testTryLockCallback,
}
switch options.Granularity {
case PerKeyGranularity:
lock.perKeyLocks = make(map[string]*_LockImp)
case ShardedGranularity:
lock.shardedLocks = make([]*sync.RWMutex, options.LockCount)
for i := range lock.shardedLocks {
lock.shardedLocks[i] = &sync.RWMutex{}
}
}
return &lock
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/sharded_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/sharded_client.go#L24-L32 | go | train | // This creates a new ShardedClient. | func NewShardedClient(
manager ShardManager,
builder ClientShardBuilder) Client | // This creates a new ShardedClient.
func NewShardedClient(
manager ShardManager,
builder ClientShardBuilder) Client | {
return &ShardedClient{
manager: manager,
builder: builder,
}
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/sharded_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/sharded_client.go#L57-L80 | go | train | // See Client interface for documentation. | func (c *ShardedClient) Get(key string) GetResponse | // See Client interface for documentation.
func (c *ShardedClient) Get(key string) GetResponse | {
shard, conn, err := c.manager.GetShard(key)
if shard == -1 {
return NewGetErrorResponse(key, c.unmappedError(key))
}
if err != nil {
return NewGetErrorResponse(key, c.connectionError(shard, err))
}
if conn == nil {
// NOTE: zero is an invalid version id.
return NewGetResponse(key, StatusKeyNotFound, 0, nil, 0)
}
client := c.builder(shard, conn)
defer c.release(client, conn)
result := client.Get(key)
if client.IsValidState() {
getOkByAddr.Add(conn.Key().Address, 1)
} else {
getErrByAddr.Add(conn.Key().Address, 1)
}
return result
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/sharded_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/sharded_client.go#L123-L125 | go | train | // See Client interface for documentation. | func (c *ShardedClient) GetMulti(keys []string) map[string]GetResponse | // See Client interface for documentation.
func (c *ShardedClient) GetMulti(keys []string) map[string]GetResponse | {
return c.getMulti(c.manager.GetShardsForKeys(keys))
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/sharded_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/sharded_client.go#L128-L130 | go | train | // See Client interface for documentation. | func (c *ShardedClient) GetSentinels(keys []string) map[string]GetResponse | // See Client interface for documentation.
func (c *ShardedClient) GetSentinels(keys []string) map[string]GetResponse | {
return c.getMulti(c.manager.GetShardsForSentinelsFromKeys(keys))
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/sharded_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/sharded_client.go#L236-L257 | go | train | // See Client interface for documentation. | func (c *ShardedClient) mutateMulti(
shards map[int]*ShardMapping,
mutateMultiFunc func(Client, *ShardMapping) []MutateResponse) []MutateResponse | // See Client interface for documentation.
func (c *ShardedClient) mutateMulti(
shards map[int]*ShardMapping,
mutateMultiFunc func(Client, *ShardMapping) []MutateResponse) []MutateResponse | {
numKeys := 0
resultsChannel := make(chan []MutateResponse, len(shards))
for shard, mapping := range shards {
numKeys += len(mapping.Keys)
go c.mutateMultiHelper(
mutateMultiFunc,
shard,
mapping,
resultsChannel)
}
results := make([]MutateResponse, 0, numKeys)
for i := 0; i < len(shards); i++ {
results = append(results, (<-resultsChannel)...)
}
return results
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/sharded_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/sharded_client.go#L260-L262 | go | train | // A helper used to specify a SetMulti mutation operation on a shard client. | func setMultiMutator(shardClient Client, mapping *ShardMapping) []MutateResponse | // A helper used to specify a SetMulti mutation operation on a shard client.
func setMultiMutator(shardClient Client, mapping *ShardMapping) []MutateResponse | {
return shardClient.SetMulti(mapping.Items)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/sharded_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/sharded_client.go#L265-L267 | go | train | // A helper used to specify a CasMulti mutation operation on a shard client. | func casMultiMutator(shardClient Client, mapping *ShardMapping) []MutateResponse | // A helper used to specify a CasMulti mutation operation on a shard client.
func casMultiMutator(shardClient Client, mapping *ShardMapping) []MutateResponse | {
return shardClient.CasMulti(mapping.Items)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/sharded_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/sharded_client.go#L270-L272 | go | train | // See Client interface for documentation. | func (c *ShardedClient) SetMulti(items []*Item) []MutateResponse | // See Client interface for documentation.
func (c *ShardedClient) SetMulti(items []*Item) []MutateResponse | {
return c.mutateMulti(c.manager.GetShardsForItems(items), setMultiMutator)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/sharded_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/sharded_client.go#L275-L277 | go | train | // See Client interface for documentation. | func (c *ShardedClient) SetSentinels(items []*Item) []MutateResponse | // See Client interface for documentation.
func (c *ShardedClient) SetSentinels(items []*Item) []MutateResponse | {
return c.mutateMulti(c.manager.GetShardsForSentinelsFromItems(items), setMultiMutator)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/sharded_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/sharded_client.go#L280-L282 | go | train | // See Client interface for documentation. | func (c *ShardedClient) CasMulti(items []*Item) []MutateResponse | // See Client interface for documentation.
func (c *ShardedClient) CasMulti(items []*Item) []MutateResponse | {
return c.mutateMulti(c.manager.GetShardsForItems(items), casMultiMutator)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/sharded_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/sharded_client.go#L285-L287 | go | train | // See Client interface for documentation. | func (c *ShardedClient) CasSentinels(items []*Item) []MutateResponse | // See Client interface for documentation.
func (c *ShardedClient) CasSentinels(items []*Item) []MutateResponse | {
return c.mutateMulti(c.manager.GetShardsForSentinelsFromItems(items), casMultiMutator)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/sharded_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/sharded_client.go#L299-L301 | go | train | // A helper used to specify a AddMulti mutation operation on a shard client. | func addMultiMutator(shardClient Client, mapping *ShardMapping) []MutateResponse | // A helper used to specify a AddMulti mutation operation on a shard client.
func addMultiMutator(shardClient Client, mapping *ShardMapping) []MutateResponse | {
return shardClient.AddMulti(mapping.Items)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/sharded_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/sharded_client.go#L304-L306 | go | train | // See Client interface for documentation. | func (c *ShardedClient) AddMulti(items []*Item) []MutateResponse | // See Client interface for documentation.
func (c *ShardedClient) AddMulti(items []*Item) []MutateResponse | {
return c.mutateMulti(c.manager.GetShardsForItems(items), addMultiMutator)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/sharded_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/sharded_client.go#L309-L315 | go | train | // See Client interface for documentation. | func (c *ShardedClient) Replace(item *Item) MutateResponse | // See Client interface for documentation.
func (c *ShardedClient) Replace(item *Item) MutateResponse | {
return c.mutate(
item.Key,
func(shardClient Client) MutateResponse {
return shardClient.Replace(item)
})
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/sharded_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/sharded_client.go#L318-L324 | go | train | // See Client interface for documentation. | func (c *ShardedClient) Delete(key string) MutateResponse | // See Client interface for documentation.
func (c *ShardedClient) Delete(key string) MutateResponse | {
return c.mutate(
key,
func(shardClient Client) MutateResponse {
return shardClient.Delete(key)
})
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/sharded_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/sharded_client.go#L327-L329 | go | train | // A helper used to specify a DeleteMulti mutation operation on a shard client. | func deleteMultiMutator(shardClient Client, mapping *ShardMapping) []MutateResponse | // A helper used to specify a DeleteMulti mutation operation on a shard client.
func deleteMultiMutator(shardClient Client, mapping *ShardMapping) []MutateResponse | {
return shardClient.DeleteMulti(mapping.Keys)
} |
dropbox/godropbox | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | memcache/sharded_client.go | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/sharded_client.go#L332-L334 | go | train | // See Client interface for documentation. | func (c *ShardedClient) DeleteMulti(keys []string) []MutateResponse | // See Client interface for documentation.
func (c *ShardedClient) DeleteMulti(keys []string) []MutateResponse | {
return c.mutateMulti(c.manager.GetShardsForKeys(keys), deleteMultiMutator)
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.