Code Monkey home page Code Monkey logo

boltstore's Introduction

Website about Keiji Yoshida

Yosssi

Installation

$ go get -u github.com/yosssi/yoss.si

Execution

$ MARTINI_ENV=production yoss.si

boltstore's People

Contributors

mjdsys avatar r0l1 avatar yosssi 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

boltstore's Issues

Reaper prevKey false assignment

I was interested in bolt and how this session store is set up. By implementing my own session store, I found a serious bug in the reap fuction in reaper.go file line 63:

if options.BatchSize == i {
   copy(prevKey, k)
   return nil
}

prevKey will always be nil, because copy will do the following thing:

The copy built-in function copies elements from a source slice into a destination slice. (As a special case, it also will copy bytes from a string to a slice of bytes.) The source and destination may overlap. Copy returns the number of elements copied, which WILL BE THE MINIMUM of len(src) and len(dst).

The reaper will always scan the first few database values until the BatchSize is reached. During the next reap process, the reaper should continue at the last key, but instead it will start from the beginning again.

A possible fix would be the following;

if options.BatchSize == i {
   // Store the current key to the previous key.
   // Copy the byte slice key, because this data is
   // not safe outside of this transaction.
   prevKey = make([]byte, len(k))
   copy(prevKey, k)
   return nil
}

Greetings

Batch multiple database write transactions into one single transaction

Please batch all those bold database write transactions into one single transaction to improve performance:

Sequential write performance is also fast but random writes can be slow. You can add a write-ahead log or transaction coalescer in front of Bolt to mitigate this issue.

Don't remove each expired session in a new transaction. Cache all expired session IDs into a byte slice and remove them all at once in a single transaction.

if shared.Expired(session) {
   err := db.Update(func(txu *bolt.Tx) error {
      return txu.Bucket(options.BucketName).Delete(k)
   })
}

I would also consider to remove the unnecessary database transaction in store.go line 90. Just return an error. The expired session will be removed from the reaper anyway. This will improve the bolt database performance.

Greetings

hang in load()

In using this at scale I see a hang in load() around line 90.
I'm now testing a version that puts Update() after View():

func (s *Store) load(session *sessions.Session) (bool, error) {
	// exists represents whether a session data exists or not.
	var exists, expired bool
	id := []byte(session.ID)
	err := s.db.View(func(tx *bolt.Tx) error {
		bucket := tx.Bucket(s.config.DBOptions.BucketName)
		// Get the session data.
		data := bucket.Get(id)
		if data == nil {
			return nil
		}
		sessionData, err := shared.Session(data)
		if err != nil {
			return err
		}
		// Check the expiration of the session data.
		if shared.Expired(sessionData) {
			expired = true
		}
		exists = true
		dec := gob.NewDecoder(bytes.NewBuffer(sessionData.Values))
		return dec.Decode(&session.Values)
	})
	if expired {
		err := s.db.Update(func(txu *bolt.Tx) error {
			return txu.Bucket(s.config.DBOptions.BucketName).Delete(id)
		})
		return false, err
	}
	return exists, err
}

cut new version for go modules to pick up

Hi @yosssi, thanks a lot for the great package.
While using it, I stumbled upon the issue with code.google.com/p/gogoprotobuf.
I saw that it had been fixed in master, but Go Modules default to the nearest release version.
Is it reasonable to cut a new minor version in order for Go Modules to default to that?

reaper: add support for a pre-delete hook

Hi @yosssi! Again, thanks a lot for this package, it has been very useful to us for this project:
https://github.com/arrikto/oidc-authservice

A new need has come up to do additional work before a session is reaped.
For example, we need to revoke tokens at a remote endpoint.
I have prepared and will open a PR for this functionality, if you are willing to accept.
I understand that you may not have the time to help, in which case we would have to use our own fork.

Make Options world accesible

In terms to manage Options outside boltstore, it would be nice to have either config public or enable a method to update those values.

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.