From 38664d7f3947076a3ce48eb01276fc097bf842d2 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 29 Nov 2019 00:40:49 +0800 Subject: [PATCH] upgrade levelqueue to 0.1.0 (#9192) (#9199) --- go.mod | 2 +- go.sum | 4 +- modules/indexer/issues/queue_disk.go | 2 +- vendor/gitea.com/lunny/levelqueue/.drone.yml | 23 +++++++ .../lunny/levelqueue/.gitignore | 0 .../lunny/levelqueue/LICENSE | 0 vendor/gitea.com/lunny/levelqueue/README.md | 28 ++++++++ .../lunny/levelqueue/error.go | 0 vendor/gitea.com/lunny/levelqueue/go.mod | 8 +++ .../lunny/levelqueue/go.sum | 20 ++++++ .../lunny/levelqueue/queue.go | 65 ++++++++++++++++--- vendor/github.com/lunny/levelqueue/README.md | 23 ------- vendor/github.com/lunny/levelqueue/go.mod | 3 - vendor/modules.txt | 4 +- 14 files changed, 142 insertions(+), 40 deletions(-) create mode 100644 vendor/gitea.com/lunny/levelqueue/.drone.yml rename vendor/{github.com => gitea.com}/lunny/levelqueue/.gitignore (100%) rename vendor/{github.com => gitea.com}/lunny/levelqueue/LICENSE (100%) create mode 100644 vendor/gitea.com/lunny/levelqueue/README.md rename vendor/{github.com => gitea.com}/lunny/levelqueue/error.go (100%) create mode 100644 vendor/gitea.com/lunny/levelqueue/go.mod rename vendor/{github.com => gitea.com}/lunny/levelqueue/go.sum (50%) rename vendor/{github.com => gitea.com}/lunny/levelqueue/queue.go (76%) delete mode 100644 vendor/github.com/lunny/levelqueue/README.md delete mode 100644 vendor/github.com/lunny/levelqueue/go.mod diff --git a/go.mod b/go.mod index 8e7eb3585..84c229d0b 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.13 require ( cloud.google.com/go v0.45.0 // indirect + gitea.com/lunny/levelqueue v0.1.0 gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b gitea.com/macaron/cache v0.0.0-20190822004001-a6e7fee4ee76 gitea.com/macaron/captcha v0.0.0-20190822015246-daa973478bae @@ -67,7 +68,6 @@ require ( github.com/lafriks/xormstore v1.3.1 github.com/lib/pq v1.2.0 github.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96 - github.com/lunny/levelqueue v0.0.0-20190217115915-02b525a4418e github.com/mailru/easyjson v0.7.0 // indirect github.com/markbates/goth v1.56.0 github.com/mattn/go-isatty v0.0.7 diff --git a/go.sum b/go.sum index 9eaeba3d6..67cb20ff8 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,8 @@ cloud.google.com/go v0.45.0 h1:bALuGBSgE+BD4rxsopAYlqjcwqcQtye6pWG4bC3N/k0= cloud.google.com/go v0.45.0/go.mod h1:452BcPOeI9AZfbvDw0Tbo7D32wA+WX9WME8AZwMEDZU= cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +gitea.com/lunny/levelqueue v0.1.0 h1:7wMk0VH6mvKN6vZEZCy9nUDgRmdPLgeNrm1NkW8EHNk= +gitea.com/lunny/levelqueue v0.1.0/go.mod h1:G7hVb908t0Bl0uk7zGSg14fyzNtxgtD9Shf04wkMK7s= gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b h1:vXt85uYV17KURaUlhU7v4GbCShkqRZDSfo0TkC0YCjQ= gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b/go.mod h1:Cxadig6POWpPYYSfg23E7jo35Yf0yvsdC1lifoKWmPo= gitea.com/macaron/cache v0.0.0-20190822004001-a6e7fee4ee76 h1:mMsMEg90c5KXQgRWsH8D6GHXfZIW1RAe5S9VYIb12lM= @@ -391,8 +393,6 @@ github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96 h1:uNwtsDp7ci48vBTTxDuwcoTXz4lwtDTe7TjCQ0noaWY= github.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96/go.mod h1:mmIfjCSQlGYXmJ95jFN84AkQFnVABtKuJL8IrzwvUKQ= -github.com/lunny/levelqueue v0.0.0-20190217115915-02b525a4418e h1:GSprKUrG9wNgwQgROvjPGXmcZrg4OLslOuZGB0uJjx8= -github.com/lunny/levelqueue v0.0.0-20190217115915-02b525a4418e/go.mod h1:rQZVENnBOiVakCs97XvclbwJRTAv77CRFWcYVNDkVf8= github.com/lunny/log v0.0.0-20160921050905-7887c61bf0de h1:nyxwRdWHAVxpFcDThedEgQ07DbcRc5xgNObtbTp76fk= github.com/lunny/log v0.0.0-20160921050905-7887c61bf0de/go.mod h1:3q8WtuPQsoRbatJuy3nvq/hRSvuBJrHHr+ybPPiNvHQ= github.com/lunny/nodb v0.0.0-20160621015157-fc1ef06ad4af h1:UaWHNBdukWrSG3DRvHFR/hyfg681fceqQDYVTBncKfQ= diff --git a/modules/indexer/issues/queue_disk.go b/modules/indexer/issues/queue_disk.go index b127f8d26..d6187f2ac 100644 --- a/modules/indexer/issues/queue_disk.go +++ b/modules/indexer/issues/queue_disk.go @@ -10,7 +10,7 @@ import ( "code.gitea.io/gitea/modules/log" - "github.com/lunny/levelqueue" + "gitea.com/lunny/levelqueue" ) var ( diff --git a/vendor/gitea.com/lunny/levelqueue/.drone.yml b/vendor/gitea.com/lunny/levelqueue/.drone.yml new file mode 100644 index 000000000..883b79699 --- /dev/null +++ b/vendor/gitea.com/lunny/levelqueue/.drone.yml @@ -0,0 +1,23 @@ +--- +kind: pipeline +name: test + +workspace: + base: /go + path: src/gitea.com/lunny/levelqueue + +steps: +- name: test + pull: default + image: golang:1.13 + commands: + - go get -t -d -v ./... + - go build -v + - go test -v -race -coverprofile=coverage.txt -covermode=atomic + environment: + GO111MODULE: "on" + GOPROXY: https://goproxy.cn + when: + event: + - push + - pull_request \ No newline at end of file diff --git a/vendor/github.com/lunny/levelqueue/.gitignore b/vendor/gitea.com/lunny/levelqueue/.gitignore similarity index 100% rename from vendor/github.com/lunny/levelqueue/.gitignore rename to vendor/gitea.com/lunny/levelqueue/.gitignore diff --git a/vendor/github.com/lunny/levelqueue/LICENSE b/vendor/gitea.com/lunny/levelqueue/LICENSE similarity index 100% rename from vendor/github.com/lunny/levelqueue/LICENSE rename to vendor/gitea.com/lunny/levelqueue/LICENSE diff --git a/vendor/gitea.com/lunny/levelqueue/README.md b/vendor/gitea.com/lunny/levelqueue/README.md new file mode 100644 index 000000000..80a0853cf --- /dev/null +++ b/vendor/gitea.com/lunny/levelqueue/README.md @@ -0,0 +1,28 @@ +# levelqueue + +Level queue is a simple queue golang library base on go-leveldb. + +[![Build Status](https://drone.gitea.com/api/badges/lunny/levelqueue/status.svg)](https://drone.gitea.com/lunny/levelqueue) [![](http://gocover.io/_badge/gitea.com/lunny/levelqueue)](http://gocover.io/gitea.com/lunny/levelqueue) +[![](https://goreportcard.com/badge/gitea.com/lunny/levelqueue)](https://goreportcard.com/report/gitea.com/lunny/levelqueue) + +## Installation + +``` +go get gitea.com/lunny/levelqueue +``` + +## Usage + +```Go +queue, err := levelqueue.Open("./queue") + +err = queue.RPush([]byte("test")) + +// pop an element from left of the queue +data, err = queue.LPop() + +// if handle success, element will be pop, otherwise it will be keep +queue.LHandle(func(dt []byte) error{ + return nil +}) +``` \ No newline at end of file diff --git a/vendor/github.com/lunny/levelqueue/error.go b/vendor/gitea.com/lunny/levelqueue/error.go similarity index 100% rename from vendor/github.com/lunny/levelqueue/error.go rename to vendor/gitea.com/lunny/levelqueue/error.go diff --git a/vendor/gitea.com/lunny/levelqueue/go.mod b/vendor/gitea.com/lunny/levelqueue/go.mod new file mode 100644 index 000000000..8b3e56518 --- /dev/null +++ b/vendor/gitea.com/lunny/levelqueue/go.mod @@ -0,0 +1,8 @@ +module gitea.com/lunny/levelqueue + +require ( + github.com/stretchr/testify v1.3.0 + github.com/syndtr/goleveldb v0.0.0-20190203031304-2f17a3356c66 +) + +go 1.13 diff --git a/vendor/github.com/lunny/levelqueue/go.sum b/vendor/gitea.com/lunny/levelqueue/go.sum similarity index 50% rename from vendor/github.com/lunny/levelqueue/go.sum rename to vendor/gitea.com/lunny/levelqueue/go.sum index 5936aa865..7ae187338 100644 --- a/vendor/github.com/lunny/levelqueue/go.sum +++ b/vendor/gitea.com/lunny/levelqueue/go.sum @@ -1,18 +1,38 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/syndtr/goleveldb v0.0.0-20190203031304-2f17a3356c66 h1:AwmkkZT+TucFotNCL+aNJ/0KCMsRtlXN9fs8uoOMSRk= github.com/syndtr/goleveldb v0.0.0-20190203031304-2f17a3356c66/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/vendor/github.com/lunny/levelqueue/queue.go b/vendor/gitea.com/lunny/levelqueue/queue.go similarity index 76% rename from vendor/github.com/lunny/levelqueue/queue.go rename to vendor/gitea.com/lunny/levelqueue/queue.go index 0b2bef6c8..af624db8e 100644 --- a/vendor/github.com/lunny/levelqueue/queue.go +++ b/vendor/gitea.com/lunny/levelqueue/queue.go @@ -140,25 +140,25 @@ func (queue *Queue) RPush(data []byte) error { // LPush pushes a data from left of queue func (queue *Queue) LPush(data []byte) error { - queue.highLock.Lock() + queue.lowLock.Lock() id, err := queue.lowdecrement() if err != nil { - queue.highLock.Unlock() + queue.lowLock.Unlock() return err } err = queue.db.Put(id2bytes(id), data, nil) - queue.highLock.Unlock() + queue.lowLock.Unlock() return err } // RPop pop a data from right of queue func (queue *Queue) RPop() ([]byte, error) { queue.highLock.Lock() + defer queue.highLock.Unlock() currentID := queue.high res, err := queue.db.Get(id2bytes(currentID), nil) if err != nil { - queue.highLock.Unlock() if err == leveldb.ErrNotFound { return nil, ErrNotFound } @@ -167,26 +167,50 @@ func (queue *Queue) RPop() ([]byte, error) { _, err = queue.highdecrement() if err != nil { - queue.highLock.Unlock() return nil, err } err = queue.db.Delete(id2bytes(currentID), nil) - queue.highLock.Unlock() if err != nil { return nil, err } return res, nil } +// RHandle receives a user callback function to handle the right element of the queue, if function return nil, then delete the element, otherwise keep the element. +func (queue *Queue) RHandle(h func([]byte) error) error { + queue.highLock.Lock() + defer queue.highLock.Unlock() + currentID := queue.high + + res, err := queue.db.Get(id2bytes(currentID), nil) + if err != nil { + if err == leveldb.ErrNotFound { + return ErrNotFound + } + return err + } + + if err = h(res); err != nil { + return err + } + + _, err = queue.highdecrement() + if err != nil { + return err + } + + return queue.db.Delete(id2bytes(currentID), nil) +} + // LPop pop a data from left of queue func (queue *Queue) LPop() ([]byte, error) { queue.lowLock.Lock() + defer queue.lowLock.Unlock() currentID := queue.low res, err := queue.db.Get(id2bytes(currentID), nil) if err != nil { - queue.lowLock.Unlock() if err == leveldb.ErrNotFound { return nil, ErrNotFound } @@ -199,13 +223,38 @@ func (queue *Queue) LPop() ([]byte, error) { } err = queue.db.Delete(id2bytes(currentID), nil) - queue.lowLock.Unlock() if err != nil { return nil, err } return res, nil } +// LHandle receives a user callback function to handle the left element of the queue, if function return nil, then delete the element, otherwise keep the element. +func (queue *Queue) LHandle(h func([]byte) error) error { + queue.lowLock.Lock() + defer queue.lowLock.Unlock() + currentID := queue.low + + res, err := queue.db.Get(id2bytes(currentID), nil) + if err != nil { + if err == leveldb.ErrNotFound { + return ErrNotFound + } + return err + } + + if err = h(res); err != nil { + return err + } + + _, err = queue.lowincrement() + if err != nil { + return err + } + + return queue.db.Delete(id2bytes(currentID), nil) +} + // Close closes the queue func (queue *Queue) Close() error { err := queue.db.Close() diff --git a/vendor/github.com/lunny/levelqueue/README.md b/vendor/github.com/lunny/levelqueue/README.md deleted file mode 100644 index 3d9fc097b..000000000 --- a/vendor/github.com/lunny/levelqueue/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# levelqueue - -Level queue is a simple queue golang library base on go-leveldb. - -[![CircleCI](https://circleci.com/gh/lunny/levelqueue.svg?style=shield)](https://circleci.com/gh/lunny/levelqueue) -[![codecov](https://codecov.io/gh/lunny/levelqueue/branch/master/graph/badge.svg)](https://codecov.io/gh/lunny/levelqueue) -[![](https://goreportcard.com/badge/github.com/lunny/levelqueue)](https://goreportcard.com/report/github.com/lunny/levelqueue) - -## Installation - -``` -go get github.com/lunny/levelqueue -``` - -## Usage - -```Go -queue, err := levelqueue.Open("./queue") - -err = queue.RPush([]byte("test")) - -data, err = queue.LPop() -``` \ No newline at end of file diff --git a/vendor/github.com/lunny/levelqueue/go.mod b/vendor/github.com/lunny/levelqueue/go.mod deleted file mode 100644 index 7d060fc09..000000000 --- a/vendor/github.com/lunny/levelqueue/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/lunny/levelqueue - -require github.com/syndtr/goleveldb v0.0.0-20190203031304-2f17a3356c66 diff --git a/vendor/modules.txt b/vendor/modules.txt index 5f7cf2ede..0816e2a86 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,5 +1,7 @@ # cloud.google.com/go v0.45.0 cloud.google.com/go/compute/metadata +# gitea.com/lunny/levelqueue v0.1.0 +gitea.com/lunny/levelqueue # gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b gitea.com/macaron/binding # gitea.com/macaron/cache v0.0.0-20190822004001-a6e7fee4ee76 @@ -290,8 +292,6 @@ github.com/lib/pq/oid github.com/lib/pq/scram # github.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96 github.com/lunny/dingtalk_webhook -# github.com/lunny/levelqueue v0.0.0-20190217115915-02b525a4418e -github.com/lunny/levelqueue # github.com/lunny/log v0.0.0-20160921050905-7887c61bf0de github.com/lunny/log # github.com/lunny/nodb v0.0.0-20160621015157-fc1ef06ad4af