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

Scale down feature #1

Merged
merged 4 commits into from
May 22, 2017
Merged

Scale down feature #1

merged 4 commits into from
May 22, 2017

Conversation

henrod
Copy link
Contributor

@henrod henrod commented May 19, 2017

Scale Down

How it's done

  • Get from config/local.yaml how many room to remove per scale down
  • Using this amount N, it access redis and get N random rooms that have status ready
  • Remove their pods and services
  • Remove their keys from Redis
  • In GetSchedulerScalingInfo function, when a scheduler doesn't exist on DB it doesn't return error. Instead it just don't set any value on scheduler variable. So I am checking if YAML property is empty.

@henrod henrod closed this May 19, 2017
@henrod henrod reopened this May 19, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 86.265% when pulling 6374e1f on feat/scale-down into 2cf0bc0 on master.

Copy link
Contributor

@cscatolini cscatolini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm requesting changes mostly because of the modification in deleteSchedulerHelper. Fix it and I'll approve the PR.
Other than that, great job =)


l.Debug("accessing redis")
pipe := redisClient.TxPipeline()
sReady := pipe.SPopN(models.GetRoomStatusSetRedisKey(scheduler.Name, models.StatusReady), int64(amount))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never knew redis had a SPopN method. Cool 😎

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If your are calling just one method in redis there's no need for a txpipeline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I need access to github.com/topfreegames/extensions to add this new method to RedisClient interface

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! You should be able to commit and push to github.com/topfreegames/extensions

sReady := pipe.SPopN(models.GetRoomStatusSetRedisKey(scheduler.Name, models.StatusReady), int64(amount))
_, err := pipe.Exec()
if err != nil {
l.WithError(err).Error("scale down error")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a better message here so we can distinguish this error from the one below: "failed to retrieve ready rooms from redis" maybe?

@@ -272,6 +349,14 @@ func deleteSchedulerHelper(logger logrus.FieldLogger, mr *models.MixedMetricsRep
}
}

err = mr.WithSegment(models.SegmentDelete, func() error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you move the scheduler removal from db to the first operation? It was the last beacause if something failed, the watcher would recreate the other parts (namespace, redis info, etc) and if the user still wanted to delete the scheduler he could call the endpoint again.

If you first delete it from the db and then attempt to do the remaining ops when there's a failure we'll have junk info (maybe a namespace, junk info in redis, etc) that we won't be able to detect easily.

Please move it back to the last op and add a comment just above it explaining why this is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense.
I changed it because when I deleted a scheduler, the namespace was recreated without services and pods. I thought it was because the line on DB was not deleted, but actually just moving CreateNamespaceIfNecessary solved the problem.
I will move it back.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the watcher should recreate it with services and pods. This might be a bug so please take some time to make sure it works as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, the problem was calling CreateNamespaceIfNecessary before GetSchedulerScalingInfo

})

err = controller.CreateNamespaceIfNecessary(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok this makes sense. We'll just create the namespace if the scheduler still exists in the db.

@henrod henrod force-pushed the feat/scale-down branch 3 times, most recently from 23b8a40 to 6575424 Compare May 21, 2017 20:22
@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 86.228% when pulling 957f456 on feat/scale-down into 2cf0bc0 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 86.336% when pulling 6076d48 on feat/scale-down into 2cf0bc0 on master.

@@ -332,13 +403,17 @@ func deleteSchedulerHelper(logger logrus.FieldLogger, mr *models.MixedMetricsRep
}
}

// Delete from DB must be the last operation because
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, thanks

Copy link
Contributor

@cscatolini cscatolini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job

@cscatolini cscatolini merged commit abac37f into master May 22, 2017
@henrod henrod deleted the feat/scale-down branch May 23, 2017 12:40
@henrod henrod restored the feat/scale-down branch May 23, 2017 19:34
@henrod henrod deleted the feat/scale-down branch May 23, 2017 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants