Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix versioning. Remove objMap. #243

Open
wants to merge 94 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
9e0518a
create bucket_usage_log table and add file_counts, last_usage_update_…
hopkings2008 May 16, 2019
79ba769
replace the redigo with go_redis.
hopkings2008 May 20, 2019
edffbf4
add Ping cmd for redis client.
hopkings2008 May 21, 2019
449bbe4
change to use the new Ping of redis client.
hopkings2008 May 21, 2019
9c5f367
add check for redis client.
hopkings2008 May 21, 2019
b0b3d4c
change the typo.
hopkings2008 May 21, 2019
cc9e5b7
remove last_usage_update_time.
hopkings2008 May 21, 2019
c0df677
set addrs for redis cluster client.
hopkings2008 May 21, 2019
e224ade
check pool_size before set it into options.
hopkings2008 May 21, 2019
45e926e
refine cache Get function.
hopkings2008 May 21, 2019
333fea5
update the usage in cache and scheduler a job to sync the usage.
hopkings2008 May 23, 2019
4bd80fa
fix compiler error in storage.go
hopkings2008 May 23, 2019
58da5ba
use meta Stop method.
hopkings2008 May 23, 2019
2978cdf
check whether the returned cache bucket is empty.
hopkings2008 May 23, 2019
075434b
check the length the related bucket usages container.
hopkings2008 May 23, 2019
43da09f
remove the bucket usage cache from redis.
hopkings2008 May 23, 2019
fbe7b3a
don't use the highwayhash for redis key.
hopkings2008 May 23, 2019
fff071f
use redis hashmap to store the cache.
hopkings2008 May 27, 2019
273f2ea
change storage to use the use defined cache functions.
hopkings2008 May 27, 2019
faa7044
add bucket_test.go
hopkings2008 May 27, 2019
4f17cb2
use valid pointer for msgunpack api.
hopkings2008 May 27, 2019
7119fc4
during start, if there is invalid cache, then update it again.
hopkings2008 May 27, 2019
1e77226
use bucket pointer instead of bucket struct.
hopkings2008 May 27, 2019
4e1c4d3
use *Bucket instead of Bucket.
hopkings2008 May 27, 2019
4eb0ef8
check where bucket pointer is nil.
hopkings2008 May 27, 2019
c78aa9d
update mod to pick new modules.
hopkings2008 May 27, 2019
879f148
set addrs for redis.
hopkings2008 May 27, 2019
121c0c3
fix the bug for test cases.
hopkings2008 May 28, 2019
afd9faf
check the error of go-redis, if it is redis.Nil, just return nil.
hopkings2008 May 28, 2019
4064164
add bucket usage sync event to sync queue.
hopkings2008 May 29, 2019
fd86ebb
close the redis when yig stop.
hopkings2008 May 29, 2019
b213227
add ci tests for bucket usage update.
hopkings2008 May 30, 2019
2b0c436
build the ci to yigci before run the tests.
hopkings2008 May 30, 2019
7e93f53
don't build the ci.
hopkings2008 May 30, 2019
1ddda63
compile the ci test into binary.
hopkings2008 May 30, 2019
8d2cb30
enable go mod when build ci
hopkings2008 May 30, 2019
46f6c4b
remove ci test from Makefile.
hopkings2008 May 30, 2019
a190bbe
update the bucket usage for append object operation.
hopkings2008 May 31, 2019
72349b3
add multipart test cases for bucket usage.
hopkings2008 Jun 3, 2019
92719eb
set the nodes and redis mode.
hopkings2008 Jun 3, 2019
919028c
set the sentinel master name from config.
hopkings2008 Jun 3, 2019
04cecc7
for bucket usage sync event, just transfer the bucket name and its us…
hopkings2008 Jun 17, 2019
aa06ab2
set mod 644 for go.mod & go.sum
hopkings2008 Jun 17, 2019
5a78a40
rebase the changes of redis to master.
hopkings2008 Jul 9, 2019
219bd76
enhance the sync bucket usage from redis into tidb logic.
hopkings2008 Jul 25, 2019
2405473
fix compile error after rebase with master.
hopkings2008 Jul 25, 2019
46550a5
skip test/ci currently due to travis host doesn't have ceph related l…
hopkings2008 Jul 25, 2019
439dc7b
remove filecounts from buckets table.
hopkings2008 Jul 26, 2019
a107159
Merge pull request #3 from hopkings2008/redis
hopkings2008 Jul 26, 2019
ccfae01
add wocloud_iam_plugin.
hopkings2008 Jul 15, 2019
b41baea
return the pointer of WoCloud Iam client.
hopkings2008 Jul 26, 2019
a36c783
enlarge the log level when succeed to send message through message bus.
hopkings2008 Jul 30, 2019
2d80013
upgrade the rpm build no.
hopkings2008 Jul 30, 2019
e00abd5
run the putobject deleteobject to test bucket usage concurrently.
hopkings2008 Jul 31, 2019
835beb9
make some enhancement for gc and other changes according to performance
hopkings2008 Aug 14, 2019
27c5ed3
Merge pull request #4 from hopkings2008/redis
hopkings2008 Aug 14, 2019
057de22
remove the clear buffer for pool.
hopkings2008 Aug 14, 2019
a128e3c
print the ret if error happens when wait_for_pending for ceph put.
hopkings2008 Aug 15, 2019
e0963ca
Merge pull request #5 from hopkings2008/redis
hopkings2008 Aug 15, 2019
e46089b
add requestId in log message; add log level;
Jul 25, 2019
d46e290
Move context as first param and some other trivial fixes.
brucen1030 Jul 30, 2019
6e528ac
fix conflicts.
brucen1030 Sep 2, 2019
e8ea92b
Merge pull request #6 from woclouds3/wip_log_add_request_id_to_redis
hopkings2008 Sep 12, 2019
cc22705
skip bucket usage sync if cache is disabled.
hopkings2008 Sep 16, 2019
36ea2b6
do not remove the item from gc when that item is failed to delete fro…
hopkings2008 Sep 16, 2019
981998c
Merge pull request #7 from hopkings2008/redis
hopkings2008 Oct 9, 2019
d9aaec6
Add functions: Upload Archive, Delete Archive and Create Vault. Add e…
sunfengyun Oct 21, 2019
3daaa43
Add coldstorage function and some error types.
sunfengyun Oct 23, 2019
c902ced
Change some names, import and log style.
sunfengyun Oct 24, 2019
25ad1cc
Initiate Logger and change log style.
sunfengyun Oct 25, 2019
561f4af
Merge pull request #13 from sunfengyun/myredis
hopkings2008 Oct 28, 2019
382368d
Merge pull request #14 from sunfch/avocet
hopkings2008 Oct 28, 2019
3b37ef8
Merge branch 'redis' of https://github.com/woclouds3/yig into redis
hopkings2008 Oct 29, 2019
255b5b6
fix the problem of start job to sync bucket usage.
hopkings2008 Oct 30, 2019
aa07a6f
fix bucket usage sync problem.
hopkings2008 Oct 30, 2019
2738c6b
import strings in bucket.go
hopkings2008 Oct 30, 2019
96dfba7
Improve object list
sunfch Oct 31, 2019
9a92d58
Merge pull request #18 from sunfch/redis
sunfch Oct 31, 2019
7857006
Merge branch 'redis' of https://github.com/woclouds3/yig into redis
hopkings2008 Oct 31, 2019
79bfa01
Set the number of query result 10000
sunfch Oct 31, 2019
7e86f20
Merge pull request #19 from sunfch/redis
sunfch Oct 31, 2019
8e8f53c
Merge branch 'redis' of https://github.com/woclouds3/yig into redis
hopkings2008 Oct 31, 2019
a22ea73
don't add num when prefix is empty string in ListObjects.
hopkings2008 Nov 4, 2019
13e2a00
add args in log of ListObjectsts.
hopkings2008 Nov 4, 2019
70c773d
remove nullversion, deletemarker from select sql in ListObjects.
hopkings2008 Nov 4, 2019
45259aa
add order by sql in ListObjects when use group by.
hopkings2008 Nov 4, 2019
b494068
Merge pull request #17 from hopkings2008/redis
hopkings2008 Nov 4, 2019
850699e
Add iam plugin in rpm package
sunfch Nov 5, 2019
a10c484
fix the problem of removing wrong key when perform bucket delete.
hopkings2008 Nov 18, 2019
11d05c9
Merge pull request #24 from hopkings2008/redis
hopkings2008 Nov 19, 2019
b9f9144
Add yig.sql to rpm
sunfch Dec 20, 2019
4c33408
Add dummy_iam_plugin in rpm package
Dec 22, 2019
6173e5c
Fix bug that object with size of 1M cannot be deleted completely
sunfch Dec 24, 2019
18c8865
Fix versioning.
brucen1030 Feb 20, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ script:
# use chmod to reset the permission of go.mod and go.sum to make go test happy
- sudo chmod 644 go.mod go.sum
- sudo python test/sanity.py
- sudo chmod 644 go.mod go.sum
- pushd test/go
- go test -v
- popd
Expand All @@ -53,7 +54,7 @@ deploy:
file_glob: true
skip_cleanup: true
on:
repo: journeymidnight/yig
repo: woclouds3/yig
tags: true

- provider: script
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ build_internal:
cp -f delete $(PWD)/build/bin/
cp -f getrediskeys $(PWD)/build/bin/
cp -f lc $(PWD)/build/bin/

pkg:
docker run --rm -v $(PWD):/work -w /work journeymidnight/yig bash -c 'bash package/rpmbuild.sh'
image:
Expand Down
16 changes: 8 additions & 8 deletions admin-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func getUsage(w http.ResponseWriter, r *http.Request) {
claims := r.Context().Value("claims").(jwt.MapClaims)
bucketName := claims["bucket"].(string)

usage, err := adminServer.Yig.MetaStorage.GetUsage(bucketName)
usage, err := adminServer.Yig.MetaStorage.GetUsage(r.Context(), bucketName)
if err != nil {
api.WriteErrorResponse(w, r, err)
return
Expand All @@ -69,8 +69,8 @@ func getBucketInfo(w http.ResponseWriter, r *http.Request) {
claims := r.Context().Value("claims").(jwt.MapClaims)
bucketName := claims["bucket"].(string)

helper.Debugln("bucketName:", bucketName)
bucket, err := adminServer.Yig.MetaStorage.GetBucketInfo(bucketName)
helper.Debugln("[", api.RequestIdFromContext(r.Context()), "]", "bucketName:", bucketName)
bucket, err := adminServer.Yig.MetaStorage.GetBucketInfo(r.Context(), bucketName)
if err != nil {
api.WriteErrorResponse(w, r, err)
return
Expand All @@ -85,12 +85,12 @@ func getUserInfo(w http.ResponseWriter, r *http.Request) {
claims := r.Context().Value("claims").(jwt.MapClaims)
uid := claims["uid"].(string)

buckets, err := adminServer.Yig.MetaStorage.GetUserInfo(uid)
buckets, err := adminServer.Yig.MetaStorage.GetUserInfo(r.Context(), uid)
if err != nil {
api.WriteErrorResponse(w, r, err)
return
}
helper.Debugln("enter getUserInfo", uid, buckets)
helper.Debugln("[", api.RequestIdFromContext(r.Context()), "]", "enter getUserInfo", uid, buckets)

var keys []common.Credential
if helper.CONFIG.DebugMode == false {
Expand All @@ -106,12 +106,12 @@ func getUserInfo(w http.ResponseWriter, r *http.Request) {
}

func getObjectInfo(w http.ResponseWriter, r *http.Request) {
helper.Debugln("enter getObjectInfo")
helper.Debugln("[", api.RequestIdFromContext(r.Context()), "]", "enter getObjectInfo")
claims := r.Context().Value("claims").(jwt.MapClaims)
bucketName := claims["bucket"].(string)
objectName := claims["object"].(string)

object, err := adminServer.Yig.MetaStorage.GetObject(bucketName, objectName, true)
object, err := adminServer.Yig.MetaStorage.GetObject(r.Context(), bucketName, objectName, true)
if err != nil {
api.WriteErrorResponse(w, r, err)
return
Expand All @@ -122,7 +122,7 @@ func getObjectInfo(w http.ResponseWriter, r *http.Request) {
}

func getCacheHitRatio(w http.ResponseWriter, r *http.Request) {
helper.Debugln("enter getCacheHitRatio")
helper.Debugln("[", api.RequestIdFromContext(r.Context()), "]", "enter getCacheHitRatio")

rate := adminServer.Yig.MetaStorage.Cache.GetCacheHitRatio()
b, _ := json.Marshal(cacheJson{HitRate: rate})
Expand Down
30 changes: 28 additions & 2 deletions api/access-log-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"net/http"
"sync"
"time"

"github.com/journeymidnight/yig/helper"
Expand Down Expand Up @@ -40,23 +41,38 @@ type AccessLogHandler struct {
handler http.Handler
responseRecorder *ResponseRecorder
format string
mapPool *sync.Pool
replacePool *sync.Pool
}

func (a AccessLogHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
tstart := time.Now()
a.responseRecorder = NewResponseRecorder(w)

startTime := time.Now()
a.handler.ServeHTTP(a.responseRecorder, r)
finishTime := time.Now()
a.responseRecorder.requestTime = finishTime.Sub(startTime)

newReplacer := NewReplacer(r, a.responseRecorder, "-")
valueMap := a.mapPool.Get().(map[string]string)
newReplacer := NewReplacer(r, a.responseRecorder, "-", valueMap, a.replacePool)
defer func() {
for k := range valueMap {
delete(valueMap, k)
}
a.mapPool.Put(valueMap)
}()
response := newReplacer.Replace(a.format)

helper.AccessLogger.Println(5, response)
helper.AccessLogger.Println(20, response)
// send the entrys in access logger to message bus.
elems := newReplacer.GetReplacedValues()
a.notify(elems)
tend := time.Now()
dur := tend.Sub(tstart).Nanoseconds() / 1000000
if dur >= 100 {
helper.Logger.Printf(5, "slow log: access_log_handler(%s) spent %d", response, dur)
}
}

func (a AccessLogHandler) notify(elems map[string]string) {
Expand Down Expand Up @@ -99,5 +115,15 @@ func NewAccessLogHandler(handler http.Handler, _ *meta.Meta) http.Handler {
return AccessLogHandler{
handler: handler,
format: CombinedLogFormat,
mapPool: &sync.Pool{
New: func() interface{} {
return make(map[string]string)
},
},
replacePool: &sync.Pool{
New: func() interface{} {
return make([]byte, 256)
},
},
}
}
8 changes: 5 additions & 3 deletions api/api-resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
package api

import (
"context"
"net/url"
"strconv"

"unicode/utf8"

. "github.com/journeymidnight/yig/api/datatype"
. "github.com/journeymidnight/yig/error"
"github.com/journeymidnight/yig/helper"
"unicode/utf8"
)

func parseListObjectsQuery(query url.Values) (request ListObjectsRequest, err error) {
func parseListObjectsQuery(ctx context.Context, query url.Values) (request ListObjectsRequest, err error) {
if query.Get("list-type") == "2" {
request.Version = 2
request.ContinuationToken = query.Get("continuation-token")
Expand Down Expand Up @@ -60,7 +62,7 @@ func parseListObjectsQuery(query url.Values) (request ListObjectsRequest, err er
} else {
request.MaxKeys, err = strconv.Atoi(query.Get("max-keys"))
if err != nil {
helper.Debugln("Error parsing max-keys:", err)
helper.Debugln("[", RequestIdFromContext(ctx), "]", "Error parsing max-keys:", err)
return request, ErrInvalidMaxKeys
}
if request.MaxKeys > MaxObjectList || request.MaxKeys < 1 {
Expand Down
12 changes: 6 additions & 6 deletions api/api-response.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func GetObjectLocation(bucketName string, key string) string {
// Takes an array of Bucket metadata information for serialization
// input: array of bucket metadata
// output: populated struct that can be serialized to match xml and json api spec output
func GenerateListBucketsResponse(buckets []meta.Bucket, credential common.Credential) ListBucketsResponse {
func GenerateListBucketsResponse(buckets []*meta.Bucket, credential common.Credential) ListBucketsResponse {
var listBuckets []Bucket
var data = ListBucketsResponse{}
var owner = Owner{}
Expand Down Expand Up @@ -224,24 +224,24 @@ func WriteSuccessNoContent(w http.ResponseWriter) {

// writeErrorResponse write error headers
func WriteErrorResponse(w http.ResponseWriter, r *http.Request, err error) {
WriteErrorResponseHeaders(w, err)
WriteErrorResponseHeaders(w, r, err)
WriteErrorResponseNoHeader(w, r, err, r.URL.Path)
}

func WriteErrorResponseWithResource(w http.ResponseWriter, r *http.Request, err error, resource string) {
WriteErrorResponseHeaders(w, err)
WriteErrorResponseHeaders(w, r, err)
WriteErrorResponseNoHeader(w, r, err, resource)
}

func WriteErrorResponseHeaders(w http.ResponseWriter, err error) {
func WriteErrorResponseHeaders(w http.ResponseWriter, r *http.Request, err error) {
var status int
apiErrorCode, ok := err.(ApiError)
if ok {
status = apiErrorCode.HttpStatusCode()
} else {
status = http.StatusInternalServerError
}
helper.Logger.Println(5, "Response status code:", status, "err:", err)
helper.Logger.Println(5, "[", RequestIdFromContext(r.Context()), "]", "Response status code:", status, "err:", err)

//ResponseRecorder
w.(*ResponseRecorder).status = status
Expand All @@ -266,7 +266,7 @@ func WriteErrorResponseNoHeader(w http.ResponseWriter, req *http.Request, err er
errorResponse.Message = "We encountered an internal error, please try again."
}
errorResponse.Resource = resource
errorResponse.RequestId = requestIdFromContext(req.Context())
errorResponse.RequestId = RequestIdFromContext(req.Context())
errorResponse.HostId = helper.CONFIG.InstanceId

encodedErrorResponse := EncodeResponse(errorResponse)
Expand Down
22 changes: 12 additions & 10 deletions api/auth-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ func checkRequestAuth(api ObjectAPIHandlers, r *http.Request, action policy.Acti
authType := signature.GetRequestAuthType(r)
switch authType {
case signature.AuthTypeUnknown:
helper.Logger.Println(5, "ErrAccessDenied: AuthTypeUnknown")
helper.Logger.Println(5, "[", RequestIdFromContext(r.Context()), "]", "ErrAccessDenied: AuthTypeUnknown")
return c, ErrAccessDenied
case signature.AuthTypeSignedV4, signature.AuthTypePresignedV4,
signature.AuthTypePresignedV2, signature.AuthTypeSignedV2:
helper.Logger.Println(5, "AuthTypeSigned:", authType)
helper.Logger.Println(5, "[", RequestIdFromContext(r.Context()), "]", "AuthTypeSigned:", authType)
if c, err := signature.IsReqAuthenticated(r); err != nil {
helper.Logger.Println(5, "ErrAccessDenied: IsReqAuthenticated return false:", err)
helper.Logger.Println(5, "[", RequestIdFromContext(r.Context()), "]", "ErrAccessDenied: IsReqAuthenticated return false:", err)
return c, err
} else {
helper.Logger.Println(5, "Credential:", c)
helper.Logger.Println(5, "[", RequestIdFromContext(r.Context()), "]", "Credential:", c)
// check bucket policy
c, err = IsBucketPolicyAllowed(c, api, r, action, bucketName, objectName)
return c, err
Expand All @@ -45,16 +45,16 @@ func checkRequestAuth(api ObjectAPIHandlers, r *http.Request, action policy.Acti
}

func IsBucketPolicyAllowed(c common.Credential, api ObjectAPIHandlers, r *http.Request, action policy.Action, bucketName, objectName string) (common.Credential, error) {
bucket, err := api.ObjectAPI.GetBucket(bucketName)
bucket, err := api.ObjectAPI.GetBucket(r.Context(), bucketName)
if err != nil {
helper.Logger.Println(5, "GetBucket", bucketName, "err:", err)
helper.Logger.Println(5, "[", RequestIdFromContext(r.Context()), "]", "GetBucket", bucketName, "err:", err)
return c, err
}
if bucket.OwnerId == c.UserId {
return c, nil
}
helper.Logger.Println(5, "bucket.OwnerId:", bucket.OwnerId, "not equals c.UserId:", c.UserId)
helper.Debugln("GetBucketPolicy:", bucket.Policy)
helper.Logger.Println(5, "[", RequestIdFromContext(r.Context()), "]", "bucket.OwnerId:", bucket.OwnerId, "not equals c.UserId:", c.UserId)
helper.Debugln("[", RequestIdFromContext(r.Context()), "]", "GetBucketPolicy:", bucket.Policy)
policyResult := bucket.Policy.IsAllowed(policy.Args{
AccountName: c.UserId,
Action: action,
Expand All @@ -65,10 +65,12 @@ func IsBucketPolicyAllowed(c common.Credential, api ObjectAPIHandlers, r *http.R
})
if policyResult == policy.PolicyAllow {
c.AllowOtherUserAccess = true
helper.Debugln("Allow", c.UserId, "access", bucketName, "with", action, objectName)
helper.Debugln("[", RequestIdFromContext(r.Context()), "]",
"Allow", c.UserId, "access", bucketName, "with", action, objectName)
return c, nil
} else if policyResult == policy.PolicyDeny {
helper.Debugln("ErrAccessDenied: NotAllow", c.UserId, "access", bucketName, "with", action, objectName)
helper.Debugln("[", RequestIdFromContext(r.Context()), "]",
"ErrAccessDenied: NotAllow", c.UserId, "access", bucketName, "with", action, objectName)
return c, ErrAccessDenied
} else {
return c, nil
Expand Down
Loading