Skip to content

Commit

Permalink
use pointer receiver
Browse files Browse the repository at this point in the history
Signed-off-by: Liang Zheng <zhengliang0901@gmail.com>
  • Loading branch information
microyahoo authored and mulbc committed Dec 19, 2023
1 parent 3ea7679 commit 80d7bc8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
16 changes: 8 additions & 8 deletions worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func workUntilTimeout(Workqueue *Workqueue, workChannel chan WorkItem, notifyCha
}
for _, work := range *Workqueue.Queue {
switch work.(type) {
case DeleteOperation:
case *DeleteOperation:
log.Debug("Re-Running Work preparation for delete job started")
err := work.Prepare()
if err != nil {
Expand All @@ -194,7 +194,7 @@ func workUntilOps(Workqueue *Workqueue, workChannel chan WorkItem, maxOps uint64
if currentOps >= maxOps {
log.Debug("Reached OpsDeadline ... waiting for workers to finish")
for worker := 0; worker < numberOfWorker; worker++ {
workChannel <- Stopper{}
workChannel <- &Stopper{}
}
return
}
Expand All @@ -203,7 +203,7 @@ func workUntilOps(Workqueue *Workqueue, workChannel chan WorkItem, maxOps uint64
}
for _, work := range *Workqueue.Queue {
switch work.(type) {
case DeleteOperation:
case *DeleteOperation:
log.Debug("Re-Running Work preparation for delete job started")
err := work.Prepare()
if err != nil {
Expand Down Expand Up @@ -269,7 +269,7 @@ func fillWorkqueue(testConfig *common.TestCaseConfiguration, Workqueue *Workqueu
if err != nil {
log.WithError(err).Error("Could not increase operational Value - ignoring")
}
new := ReadOperation{
new := &ReadOperation{
TestName: testConfig.Name,
Bucket: bucketName,
ObjectName: fmt.Sprintf("%s%s%d", workerID, testConfig.ObjectPrefix, object),
Expand All @@ -282,7 +282,7 @@ func fillWorkqueue(testConfig *common.TestCaseConfiguration, Workqueue *Workqueu
if err != nil {
log.WithError(err).Error("Could not increase operational Value - ignoring")
}
new := ReadOperation{
new := &ReadOperation{
TestName: testConfig.Name,
Bucket: bucketName,
ObjectName: *preExistingObjects.Contents[object%preExistingObjectCount].Key,
Expand All @@ -295,7 +295,7 @@ func fillWorkqueue(testConfig *common.TestCaseConfiguration, Workqueue *Workqueu
if err != nil {
log.WithError(err).Error("Could not increase operational Value - ignoring")
}
new := WriteOperation{
new := &WriteOperation{
TestName: testConfig.Name,
Bucket: bucketName,
ObjectName: fmt.Sprintf("%s%s%d", workerID, testConfig.ObjectPrefix, object),
Expand All @@ -307,7 +307,7 @@ func fillWorkqueue(testConfig *common.TestCaseConfiguration, Workqueue *Workqueu
if err != nil {
log.WithError(err).Error("Could not increase operational Value - ignoring")
}
new := ListOperation{
new := &ListOperation{
TestName: testConfig.Name,
Bucket: bucketName,
ObjectName: fmt.Sprintf("%s%s%d", workerID, testConfig.ObjectPrefix, object),
Expand All @@ -319,7 +319,7 @@ func fillWorkqueue(testConfig *common.TestCaseConfiguration, Workqueue *Workqueu
if err != nil {
log.WithError(err).Error("Could not increase operational Value - ignoring")
}
new := DeleteOperation{
new := &DeleteOperation{
TestName: testConfig.Name,
Bucket: bucketName,
ObjectName: fmt.Sprintf("%s%s%d", workerID, testConfig.ObjectPrefix, object),
Expand Down
32 changes: 16 additions & 16 deletions worker/workItems.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func IncreaseOperationValue(operation string, value float64, Queue *Workqueue) e
}

// Prepare prepares the execution of the ReadOperation
func (op ReadOperation) Prepare() error {
func (op *ReadOperation) Prepare() error {
log.WithField("bucket", op.Bucket).WithField("object", op.ObjectName).WithField("Preexisting?", op.WorksOnPreexistingObject).Debug("Preparing ReadOperation")
if op.WorksOnPreexistingObject {
return nil
Expand All @@ -100,30 +100,30 @@ func (op ReadOperation) Prepare() error {
}

// Prepare prepares the execution of the WriteOperation
func (op WriteOperation) Prepare() error {
func (op *WriteOperation) Prepare() error {
log.WithField("bucket", op.Bucket).WithField("object", op.ObjectName).Debug("Preparing WriteOperation")
return nil
}

// Prepare prepares the execution of the ListOperation
func (op ListOperation) Prepare() error {
func (op *ListOperation) Prepare() error {
log.WithField("bucket", op.Bucket).WithField("object", op.ObjectName).Debug("Preparing ListOperation")
return putObject(housekeepingSvc, op.ObjectName, bytes.NewReader(generateRandomBytes(op.ObjectSize)), op.Bucket)
}

// Prepare prepares the execution of the DeleteOperation
func (op DeleteOperation) Prepare() error {
func (op *DeleteOperation) Prepare() error {
log.WithField("bucket", op.Bucket).WithField("object", op.ObjectName).Debug("Preparing DeleteOperation")
return putObject(housekeepingSvc, op.ObjectName, bytes.NewReader(generateRandomBytes(op.ObjectSize)), op.Bucket)
}

// Prepare does nothing here
func (op Stopper) Prepare() error {
func (op *Stopper) Prepare() error {
return nil
}

// Do executes the actual work of the ReadOperation
func (op ReadOperation) Do() error {
func (op *ReadOperation) Do() error {
log.WithField("bucket", op.Bucket).WithField("object", op.ObjectName).WithField("Preexisting?", op.WorksOnPreexistingObject).Debug("Doing ReadOperation")
start := time.Now()
err := getObject(svc, op.ObjectName, op.Bucket)
Expand All @@ -139,7 +139,7 @@ func (op ReadOperation) Do() error {
}

// Do executes the actual work of the WriteOperation
func (op WriteOperation) Do() error {
func (op *WriteOperation) Do() error {
log.WithField("bucket", op.Bucket).WithField("object", op.ObjectName).Debug("Doing WriteOperation")
start := time.Now()
err := putObject(svc, op.ObjectName, bytes.NewReader(generateRandomBytes(op.ObjectSize)), op.Bucket)
Expand All @@ -155,7 +155,7 @@ func (op WriteOperation) Do() error {
}

// Do executes the actual work of the ListOperation
func (op ListOperation) Do() error {
func (op *ListOperation) Do() error {
log.WithField("bucket", op.Bucket).WithField("object", op.ObjectName).Debug("Doing ListOperation")
start := time.Now()
_, err := listObjects(svc, op.ObjectName, op.Bucket)
Expand All @@ -170,7 +170,7 @@ func (op ListOperation) Do() error {
}

// Do executes the actual work of the DeleteOperation
func (op DeleteOperation) Do() error {
func (op *DeleteOperation) Do() error {
log.WithField("bucket", op.Bucket).WithField("object", op.ObjectName).Debug("Doing DeleteOperation")
start := time.Now()
err := deleteObject(svc, op.ObjectName, op.Bucket)
Expand All @@ -185,12 +185,12 @@ func (op DeleteOperation) Do() error {
}

// Do does nothing here
func (op Stopper) Do() error {
func (op *Stopper) Do() error {
return nil
}

// Clean removes the objects and buckets left from the previous ReadOperation
func (op ReadOperation) Clean() error {
func (op *ReadOperation) Clean() error {
if op.WorksOnPreexistingObject {
return nil
}
Expand All @@ -199,22 +199,22 @@ func (op ReadOperation) Clean() error {
}

// Clean removes the objects and buckets left from the previous WriteOperation
func (op WriteOperation) Clean() error {
func (op *WriteOperation) Clean() error {
return deleteObject(housekeepingSvc, op.ObjectName, op.Bucket)
}

// Clean removes the objects and buckets left from the previous ListOperation
func (op ListOperation) Clean() error {
func (op *ListOperation) Clean() error {
return deleteObject(housekeepingSvc, op.ObjectName, op.Bucket)
}

// Clean removes the objects and buckets left from the previous DeleteOperation
func (op DeleteOperation) Clean() error {
func (op *DeleteOperation) Clean() error {
return nil
}

// Clean does nothing here
func (op Stopper) Clean() error {
func (op *Stopper) Clean() error {
return nil
}

Expand All @@ -229,7 +229,7 @@ func DoWork(workChannel <-chan WorkItem, notifyChan <-chan struct{}, wg *sync.Wa
return
case work := <-workChannel:
switch work.(type) {
case Stopper:
case *Stopper:
log.Debug("Found the end of the work Queue - stopping")
return
}
Expand Down

0 comments on commit 80d7bc8

Please sign in to comment.