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

Add logging to trace memory usage and identify potential leaks or corruption #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions GO/custom_metadata_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "C"
import (
"reflect"
"unsafe"

"log"
"storj.io/uplink"
)

Expand All @@ -14,18 +14,21 @@ var customMetadata = map[string]string{}
//export prepare_custommetadata
// prepare_custommetadata creates a temporary SharePrefixes-Array to be filled by append_custommetadata and used by upload_set_custom_metadata2
func prepare_custommetadata() {
log.Println("prepare_custommetadata: Initializing custom metadata map")
customMetadata = make(map[string]string)
}

//export append_custommetadata
// append_custommetadata appends one CustomMetadata by providing the contents directly
func append_custommetadata(key *C.char, value *C.char){
log.Printf("append_custommetadata: Adding key=%s, value=%s\n", C.GoString(key), C.GoString(value))
customMetadata[C.GoString(key)] = C.GoString(value)
}

//export upload_set_custom_metadata2
// upload_set_custom_metadata2 sets the customMetadata on an upload
func upload_set_custom_metadata2(upload *C.UplinkUpload) *C.UplinkError {
log.Println("upload_set_custom_metadata2: Setting custom metadata on upload")
up, ok := universe.Get(upload._handle).(*Upload)
if !ok {
return mallocError(ErrInvalidHandle.New("upload"))
Expand Down Expand Up @@ -122,4 +125,4 @@ func uplink_update_object_metadata2(project *C.UplinkProject, bucket_name, objec

err := proj.UpdateObjectMetadata(proj.scope.ctx, C.GoString(bucket_name), C.GoString(object_key), customMetadata, nil)
return mallocError(err)
}
}
7 changes: 5 additions & 2 deletions GO/restrict_scope_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "C"

import (
"time"

"log"
"storj.io/uplink"
)

Expand All @@ -14,6 +14,7 @@ var shareprefixes []uplink.SharePrefix;
//export prepare_shareprefixes
// prepare_shareprefixes creates a temporary SharePrefixes-Array to be filled by append_shareprefix and used by access_share2
func prepare_shareprefixes(shareprefixesLen C.size_t) {
log.Printf("prepare_shareprefixes: Initializing shareprefixes array with length %d\n", shareprefixesLen)
ishareprefixesLen := int(shareprefixesLen)

shareprefixes = make([]uplink.SharePrefix, 0, ishareprefixesLen)
Expand All @@ -22,6 +23,7 @@ func prepare_shareprefixes(shareprefixesLen C.size_t) {
//export append_shareprefix
// append_shareprefix appends one SharePrefix by providing the contents directly
func append_shareprefix(bucket *C.char, prefix *C.char){
log.Printf("append_shareprefix: Adding bucket=%s, prefix=%s\n", C.GoString(bucket), C.GoString(prefix))
shareprefix := uplink.SharePrefix{
Bucket: C.GoString(bucket),
Prefix: C.GoString(prefix),
Expand All @@ -33,6 +35,7 @@ func append_shareprefix(bucket *C.char, prefix *C.char){
//export access_share2
// access_share2 restricts a given scope with the provided caveat and the temporary encryption shareprefixes
func access_share2(access *C.UplinkAccess, permission C.UplinkPermission) C.UplinkAccessResult { //nolint:golint
log.Println("access_share2: Restricting access with provided permission and shareprefixes")
if access == nil {
return C.UplinkAccessResult{
error: mallocError(ErrNull.New("access")),
Expand Down Expand Up @@ -69,4 +72,4 @@ func access_share2(access *C.UplinkAccess, permission C.UplinkPermission) C.Upli
return C.UplinkAccessResult{
access: (*C.UplinkAccess)(mallocHandle(universe.Add(&Access{newAccess}))),
}
}
}
8 changes: 7 additions & 1 deletion uplink.NET/uplink.NET/Models/Access.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -256,6 +256,7 @@ public string Serialize()
/// <returns>The restricted access</returns>
public Access Share(Permission permission, List<SharePrefix> prefixes)
{
Console.WriteLine("Share: Preparing to share access with permissions and prefixes");
SWIG.storj_uplink.prepare_shareprefixes((uint)prefixes.Count);

foreach (var prefix in prefixes)
Expand All @@ -268,6 +269,7 @@ public Access Share(Permission permission, List<SharePrefix> prefixes)
if (accessResult.error != null && !string.IsNullOrEmpty(accessResult.error.message))
throw new AccessShareException(accessResult.error.message);

Console.WriteLine("Share: Successfully shared access");
return new Access(accessResult.access);
}
}
Expand All @@ -286,11 +288,13 @@ public Access Share(Permission permission, List<SharePrefix> prefixes)
/// <returns>true, if overwriting worked - raises exception on error</returns>
public bool OverrideEncryptionAccess(string bucketName, string prefix, EncryptionKey encryptionKey)
{
Console.WriteLine("OverrideEncryptionAccess: Overriding encryption key for bucket: {0}, prefix: {1}", bucketName, prefix);
using (var error = SWIG.storj_uplink.uplink_access_override_encryption_key(_access, bucketName, prefix, encryptionKey._encryptionKeyResulRef.encryption_key))
{
if (error != null && !string.IsNullOrEmpty(error.message))
throw new AccessException(error.message);

Console.WriteLine("OverrideEncryptionAccess: Successfully overridden encryption key");
return true;
}
}
Expand Down Expand Up @@ -327,12 +331,14 @@ public string CreateShareURL(string bucketName, string key, bool raw, bool is_pu

public async Task RevokeAsync(Access childAccess)
{
Console.WriteLine("RevokeAsync: Revoking access");
using (UplinkError error = await Task.Run(() => SWIG.storj_uplink.uplink_revoke_access(_project, childAccess._access)).ConfigureAwait(false))
{
if (error != null && !string.IsNullOrEmpty(error.message))
{
throw new AccessRevokeException(error.message);
}
Console.WriteLine("RevokeAsync: Successfully revoked access");
}
}

Expand Down
34 changes: 29 additions & 5 deletions uplink.NET/uplink.NET/Services/BucketService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -21,63 +21,86 @@ public BucketService(Access access)

public async Task<Bucket> CreateBucketAsync(string bucketName)
{
Console.WriteLine("CreateBucketAsync: Creating bucket with name: {0}", bucketName);
using (SWIG.UplinkBucketResult bucketResult = await Task.Run(() => SWIG.storj_uplink.uplink_create_bucket(_access._project, bucketName)).ConfigureAwait(false))
{
if (bucketResult.error != null && !string.IsNullOrEmpty(bucketResult.error.message))
{
Console.WriteLine("CreateBucketAsync: Error creating bucket: {0}", bucketResult.error.message);
throw new BucketCreationException(bucketName, bucketResult.error.message);
}

var bucket = Bucket.FromSWIG(bucketResult.bucket, _access._project, bucketResult);

Console.WriteLine("CreateBucketAsync: Successfully created bucket: {0}", bucketName);
return bucket;
}
}

public async Task<Bucket> EnsureBucketAsync(string bucketName)
{
Console.WriteLine("EnsureBucketAsync: Ensuring bucket with name: {0}", bucketName);
using (SWIG.UplinkBucketResult bucketResult = await Task.Run(() => SWIG.storj_uplink.uplink_ensure_bucket(_access._project, bucketName)).ConfigureAwait(false))
{
if (bucketResult.error != null && !string.IsNullOrEmpty(bucketResult.error.message))
{
Console.WriteLine("EnsureBucketAsync: Error ensuring bucket: {0}", bucketResult.error.message);
throw new BucketCreationException(bucketName, bucketResult.error.message);
}

var bucket = Bucket.FromSWIG(bucketResult.bucket, _access._project, bucketResult);

Console.WriteLine("EnsureBucketAsync: Successfully ensured bucket: {0}", bucketName);
return bucket;
}
}

public async Task DeleteBucketAsync(string bucketName)
{
Console.WriteLine("DeleteBucketAsync: Deleting bucket with name: {0}", bucketName);
using (SWIG.UplinkBucketResult bucketResult = await Task.Run(() => SWIG.storj_uplink.uplink_delete_bucket(_access._project, bucketName)).ConfigureAwait(false))
{
if (bucketResult.error != null && !string.IsNullOrEmpty(bucketResult.error.message))
{
Console.WriteLine("DeleteBucketAsync: Error deleting bucket: {0}", bucketResult.error.message);
throw new BucketDeletionException(bucketName, bucketResult.error.message);
}
Console.WriteLine("DeleteBucketAsync: Successfully deleted bucket: {0}", bucketName);
}
}

public async Task DeleteBucketWithObjectsAsync(string bucketName)
{
Console.WriteLine("DeleteBucketWithObjectsAsync: Deleting bucket with objects, name: {0}", bucketName);
using (SWIG.UplinkBucketResult bucketResult = await Task.Run(() => SWIG.storj_uplink.uplink_delete_bucket_with_objects(_access._project, bucketName)).ConfigureAwait(false))
{
if (bucketResult.error != null && !string.IsNullOrEmpty(bucketResult.error.message))
{
Console.WriteLine("DeleteBucketWithObjectsAsync: Error deleting bucket with objects: {0}", bucketResult.error.message);
throw new BucketDeletionException(bucketName, bucketResult.error.message);
}
Console.WriteLine("DeleteBucketWithObjectsAsync: Successfully deleted bucket with objects: {0}", bucketName);
}
}

public async Task<Bucket> GetBucketAsync(string bucketName)
{
Console.WriteLine("GetBucketAsync: Retrieving bucket with name: {0}", bucketName);
using (SWIG.UplinkBucketResult bucketResult = await Task.Run(() => SWIG.storj_uplink.uplink_stat_bucket(_access._project, bucketName)).ConfigureAwait(false))
{
if (bucketResult.error != null && !string.IsNullOrEmpty(bucketResult.error.message))
{
Console.WriteLine("GetBucketAsync: Error retrieving bucket: {0}", bucketResult.error.message);
throw new BucketNotFoundException(bucketName, bucketResult.error.message);
}

var bucket = Bucket.FromSWIG(bucketResult.bucket, _access._project, bucketResult);

Console.WriteLine("GetBucketAsync: Successfully retrieved bucket: {0}", bucketName);
return bucket;
}
}

public async Task<BucketList> ListBucketsAsync(ListBucketsOptions listBucketsOptions)
{
Console.WriteLine("ListBucketsAsync: Listing buckets with options: {0}", listBucketsOptions);
var listBucketsOptionsSWIG = listBucketsOptions.ToSWIG();
_listOptions.Add(listBucketsOptionsSWIG);
using (SWIG.UplinkBucketIterator bucketIterator = await Task.Run(() => SWIG.storj_uplink.uplink_list_buckets(_access._project, listBucketsOptionsSWIG)).ConfigureAwait(false))
Expand All @@ -86,6 +109,7 @@ public async Task<BucketList> ListBucketsAsync(ListBucketsOptions listBucketsOpt
{
if (error != null && !string.IsNullOrEmpty(error.message))
{
Console.WriteLine("ListBucketsAsync: Error listing buckets: {0}", error.message);
throw new BucketListException(error.message);
}
}
Expand All @@ -97,7 +121,7 @@ public async Task<BucketList> ListBucketsAsync(ListBucketsOptions listBucketsOpt
var bucket = SWIG.storj_uplink.uplink_bucket_iterator_item(bucketIterator);
bucketList.Items.Add(Bucket.FromSWIG(bucket, _access._project));
}

Console.WriteLine("ListBucketsAsync: Successfully listed buckets");
return bucketList;
}
}
Expand Down
Loading