Giter Club home page Giter Club logo

godropbox's Introduction

godropbox GoDoc Actions Status Actions Status

Common libraries for writing go services/applications on Linux servers.

Requirements

  • Go 1.13+
  • Linux/x64

Installation

go get github.com/dropbox/godropbox

Documentation

See https://pkg.go.dev/github.com/dropbox/godropbox for modules documentation.

godropbox's People

Contributors

4578395263256 avatar aaron0x avatar acrefoot avatar adegtiar avatar anupcshan avatar arsham-f avatar aybabtme avatar chaoaero avatar danielrh avatar dcsommer avatar dctrwatson avatar fanngyuan avatar ferhatelmas avatar gnprice avatar jamwt avatar jhferris avatar kxing-dbx avatar mallipeddi avatar msolo avatar orborde avatar pattyshack avatar pborreli avatar piscesdk avatar rajatgoel avatar shawnps avatar tariq1890 avatar teisenbedropbox avatar vadimg avatar varunl avatar vsupalov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

godropbox's Issues

SqlBuilder - inserts to datetime

Can someone help us understand how we are supposed to insert a mysql DATE with an InsertStatement?

Currently we have: insertStatement.Add(sqlbuilder.Literal(time.Now())) which will escape the date with an extra set of double quotes which makes MySQL complain with: Error 1292: Incorrect date value: ''2014-08-20 11:17:53''

I feel like we aren't understanding something critical to inserting dates but so far everything else is working as designed.

BTW, we have modified (hacked) the sqltypes.go line 233 to not add the extra quotes around the time.Time value in which case our MySQL insert works fine.

document that sqlbuilder is mysql-only

Other than a couple of passing references in column.go and doc.go, it's not clear that sqlbuilder is meant to be run against mysql. Postgres barfs at least on the backticks for quoting. I have not tested it against sqlite.

It would be good to make this very clear in the package docs and README at a minimum. Do you have plans or want to support additional SQL flavors in the future?

Default value of MaxIdleConnections in net2.ConnectionPool is extremely slow

Benchmark results:

Fake dealer:
BenchmarkGetConnection-16           	 1492227	       803.2 ns/op
BenchmarkGetConnectionMaxIdle-16    	 1888982	       631.4 ns/op
Real dealer:
BenchmarkGetConnection-16           	    9052	    113356 ns/op
BenchmarkGetConnectionMaxIdle-16    	 1901071	       626.9 ns/op

Code example:

func BenchmarkGetConnection(b *testing.B) {
        // dialer := fakeDialer{}
        // mockClock := time2.MockClock{}

        options := ConnectionOptions{
                // MaxIdleConnections: 1,
                // Dial:               dialer.FakeDial,
                // NowFunc:            mockClock.Now,
        }

        pool := NewSimpleConnectionPool(options)
        pool.Register("tcp", "localhost:11211")
        b.ResetTimer();
        for i := 0; i < b.N; i++ {
                c, err := pool.Get("tcp", "localhost:6379")
                if err != nil {
                        b.Fatal(err)
                }
                c.ReleaseConnection()
        }
}

func BenchmarkGetConnectionMaxIdle(b *testing.B) {
        // dialer := fakeDialer{}
        // mockClock := time2.MockClock{}

        options := ConnectionOptions{
                MaxIdleConnections: 1,
                // Dial:               dialer.FakeDial,
                // NowFunc:            mockClock.Now,
        }

        pool := NewSimpleConnectionPool(options)
        pool.Register("tcp", "localhost:11211")
        b.ResetTimer();
        for i := 0; i < b.N; i++ {
                c, err := pool.Get("tcp", "localhost:6379")
                if err != nil {
                        b.Fatal(err)
                }
                c.ReleaseConnection()
        }
}

memcached binary client imposes restrictions on key

I noticed that the Memcached binary protocol client provided by this library performs checks on the keys and disallows certain byte values, perhaps to maintain compatibility with the ASCII protocol:

func isValidKeyChar(char byte) bool {

Could this behavior be made configurable? The documentation for the Memcached binary protocol (https://github.com/memcached/memcached/wiki/BinaryProtocolRevamped) doesn't seem to impose these restrictions, and empirically it does seem possible to set and retrieve keys that this client considers invalid (such as keys with spaces).

[net2] SimplePool, data race in tests

There's a race condition on the http.Request created in func (s *SimplePoolSuite) TestHTTP(c *C):

req, err := http.NewRequest("GET", "/", nil)
// ...
for i := 0; i < count; i++ {
    go func() {
        _, err = pool.Do(req)
        // ...
    }()
}

The race occurs when *SimplePool.Do changes the URL scheme of the request (which is shared):

func (pool *SimplePool) Do(req *http.Request) (resp *http.Response, err error) {
    // ...
    if pool.params.UseSSL {
        req.URL.Scheme = "https"
    } else {
        req.URL.Scheme = "http"
    }
    // ...
}

Similarly for (same func):

if pool.params.HostHeader != nil {
    req.URL.Host = *pool.params.HostHeader
} else {
    req.URL.Host = pool.addr
}

Running go test ./... -race on the root package (more than one are found at this time):

WARNING: DATA RACE
Write by goroutine 414:
  github.com/dropbox/godropbox/net2/http2.(*SimplePool).Do()
      /Users/antoine/gocode/src/github.com/dropbox/godropbox/net2/http2/simple_pool.go:103 +0x652
  github.com/dropbox/godropbox/net2/http2.func·008()
      /Users/antoine/gocode/src/github.com/dropbox/godropbox/net2/http2/simple_pool_test.go:36 +0x9d

Previous write by goroutine 83:
  github.com/dropbox/godropbox/net2/http2.(*SimplePool).Do()
      /Users/antoine/gocode/src/github.com/dropbox/godropbox/net2/http2/simple_pool.go:103 +0x652
  github.com/dropbox/godropbox/net2/http2.func·008()
      /Users/antoine/gocode/src/github.com/dropbox/godropbox/net2/http2/simple_pool_test.go:36 +0x9d

Goroutine 414 (running) created at:
  github.com/dropbox/godropbox/net2/http2.(*SimplePoolSuite).TestHTTP()
      /Users/antoine/gocode/src/github.com/dropbox/godropbox/net2/http2/simple_pool_test.go:39 +0x45e
  runtime.call16()
      /Users/antoine/go/src/pkg/runtime/asm_amd64.s:360 +0x31
  reflect.Value.Call()
      /Users/antoine/go/src/pkg/reflect/value.go:411 +0xed
  gopkg.in/check%2ev1.func·003()
      /Users/antoine/gocode/src/gopkg.in/check.v1/check.go:753 +0x51b
  gopkg.in/check%2ev1.func·001()
      /Users/antoine/gocode/src/gopkg.in/check.v1/check.go:648 +0xf4

Goroutine 83 (running) created at:
  github.com/dropbox/godropbox/net2/http2.(*SimplePoolSuite).TestHTTP()
      /Users/antoine/gocode/src/github.com/dropbox/godropbox/net2/http2/simple_pool_test.go:39 +0x45e
  runtime.call16()
      /Users/antoine/go/src/pkg/runtime/asm_amd64.s:360 +0x31
  reflect.Value.Call()
      /Users/antoine/go/src/pkg/reflect/value.go:411 +0xed
  gopkg.in/check%2ev1.func·003()
      /Users/antoine/gocode/src/gopkg.in/check.v1/check.go:753 +0x51b
  gopkg.in/check%2ev1.func·001()
      /Users/antoine/gocode/src/gopkg.in/check.v1/check.go:648 +0xf4

and

WARNING: DATA RACE
Write by goroutine 41:
  github.com/dropbox/godropbox/net2/http2.(*SimplePool).Do()
      /Users/antoine/gocode/src/github.com/dropbox/godropbox/net2/http2/simple_pool.go:108 +0x5d5
  github.com/dropbox/godropbox/net2/http2.func·008()
      /Users/antoine/gocode/src/github.com/dropbox/godropbox/net2/http2/simple_pool_test.go:36 +0x9d

Previous write by goroutine 83:
  github.com/dropbox/godropbox/net2/http2.(*SimplePool).Do()
      /Users/antoine/gocode/src/github.com/dropbox/godropbox/net2/http2/simple_pool.go:108 +0x5d5
  github.com/dropbox/godropbox/net2/http2.func·008()
      /Users/antoine/gocode/src/github.com/dropbox/godropbox/net2/http2/simple_pool_test.go:36 +0x9d

Goroutine 41 (running) created at:
  github.com/dropbox/godropbox/net2/http2.(*SimplePoolSuite).TestHTTP()
      /Users/antoine/gocode/src/github.com/dropbox/godropbox/net2/http2/simple_pool_test.go:39 +0x45e
  runtime.call16()
      /Users/antoine/go/src/pkg/runtime/asm_amd64.s:360 +0x31
  reflect.Value.Call()
      /Users/antoine/go/src/pkg/reflect/value.go:411 +0xed
  gopkg.in/check%2ev1.func·003()
      /Users/antoine/gocode/src/gopkg.in/check.v1/check.go:753 +0x51b
  gopkg.in/check%2ev1.func·001()
      /Users/antoine/gocode/src/gopkg.in/check.v1/check.go:648 +0xf4

Goroutine 83 (running) created at:
  github.com/dropbox/godropbox/net2/http2.(*SimplePoolSuite).TestHTTP()
      /Users/antoine/gocode/src/github.com/dropbox/godropbox/net2/http2/simple_pool_test.go:39 +0x45e
  runtime.call16()
      /Users/antoine/go/src/pkg/runtime/asm_amd64.s:360 +0x31
  reflect.Value.Call()
      /Users/antoine/go/src/pkg/reflect/value.go:411 +0xed
  gopkg.in/check%2ev1.func·003()
      /Users/antoine/gocode/src/gopkg.in/check.v1/check.go:753 +0x51b
  gopkg.in/check%2ev1.func·001()
      /Users/antoine/gocode/src/gopkg.in/check.v1/check.go:648 +0xf4

binlog for mysql 8

Does the mysql binlog package work for mysql 8 despite the readme saying max v5.6?

Add read/write timeout to connection pool

I'm a little concerned about using your memcached library on AWS without having read/write timeouts. I know I can do this by supplying a custom Dial function in ConnectionOptions that creates an instance of a custom net.Conn-implementing struct that wraps net.Conn and calls SetReadDeadline before Read, etc... but that seems a bit hacky. Especially concerning that struct's SetDeadline methods: should I return an error or pass the deadlines through to net.Conn? The code in ManagedConnImpl seems to imply that the owner connection pool reserves the right to set deadlines, so returning an error might cause issues. On the other hand, passing the deadlines through would break the contract of the net.Conn interface, since they would be re-set before every Read/Write call.

I think it would be simple to add optional explicit read/write timeouts and would be willing to send a pull request with tests, if you reply to this issue saying you'd be willing to merge it.

It would be relatively simple to add:

To the ConnectionOptions struct I would add

    ReadTimeout time.Duration
    WriteTimeout time.Duration

These timeouts would be passed to NewManagedConn and stored in ManagedConnImpl. In ManagedConnImpl's Read method, if ReadTimeout > 0, I'd call SetReadDeadline before calling conn.Read, and similarly for the Write method.

Am I missing anything? Does this sound reasonable?

Incorrect synchronization pattern in singleton.go

The file godropbox/singleton/singleton.go contains an incorrect synchronization pattern. It is assumed that s.data will always be filled correctly when s.initialized == true, but this is a false assumption. For more information, see the section on Incorrect synchronization at https://golang.org/ref/mem.

Either document that the Get() method might (theoretically) return garbage 😬 or use the sync/atomic package. For inspiration look at sync.Once (http://golang.org/src/sync/once.go?s=1139:1166#L25). 😄

resource pool Close func may not be called

Hi, guys!
There might be a bug, which seem to be ingore some resource without calling Close function in SimpleResourcePool.getIdleHandle

	if len(p.idleHandles) > 0 {
		p.idleHandles = []*idleHandle{}
	}

If goes here, it means there's no handle can be used, but why don't close them, just ingore?
I think it might be this:

	if len(p.idleHandles) > 0 {
		toClose = p.idleHandles
		p.idleHandles = []*idleHandle{}
	}

Thanks!

Wrong filename

In net2/http2 there is a file named test_utils.go, but needs to be utils_test.go.
Thanks and kudos for the useful library!

Per-request memcache client timeouts

Would you be open to a pull-request adding support for customizing the timeouts on individual memcache requests? For example, 10ms for Get() and 100ms for a later Get().

Since this is a larger change, I wanted to check with you first before digging into this.

Rough Proposal:
Pass deadline using context.Context. To keep API compatibility, introduce new interfaces for this purpose: ContextClient, ContextClientShard, ContextManagedConn etc. Have existing implementations pass context.Background() to the new methods. It should be possible to leave the existing API unchanged.

Please let me know if you'd be open to such a change, or if there's a different approach you'd prefer me to take here.

Thanks in advance,
Ben Karas
Google

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.