Skip to content

Basic implementation of MySqlAccountService #3

Open
Arun-LinkedIn wants to merge 3 commits intolightningrob:mysql-accountsfrom
Arun-LinkedIn:mysql-accounts-mybranch
Open

Basic implementation of MySqlAccountService #3
Arun-LinkedIn wants to merge 3 commits intolightningrob:mysql-accountsfrom
Arun-LinkedIn:mysql-accounts-mybranch

Conversation

@Arun-LinkedIn
Copy link

Changes implemented:

a) Fetch all accounts and container metadata from DB and initialize cache on boot-up,
b) Implement AccountService interface update APIs to write changes to mysql database and getter APIs to read changes from cache.

…ities.

a) Fetch all accounts and container metadata from DB and initialize cache on boot-up,
b) Implement AccountService interface update APIs to write changes to mysql database and getter APIs to read changes from cache.
Copy link
Owner

@lightningrob lightningrob left a comment

Choose a reason for hiding this comment

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

Good start. A few comments on the code. Tests still needed.

getByAccountSql =
String.format("select %s, %s, %s from %s where %s = ?", ACCOUNT_ID, CONTAINER_INFO, LAST_MODIFIED_TIME,
CONTAINER_TABLE, ACCOUNT_ID);
updateSql = String.format("update %s set %s = ?, %s = 1, %s = now() where %s = ? AND %s = ? ", CONTAINER_TABLE,
Copy link
Owner

Choose a reason for hiding this comment

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

You don't want to set version = 1 on update.

Copy link
Author

Choose a reason for hiding this comment

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

Sure, true. Added a todo to change it after adding version field in Container class. I think that we might need to add version field on both ambry and nuage-ambry at same time to avoid serialization/deserialization issues.

return snapshotVersion;
}

public void setStatus(AccountStatus status) {
Copy link
Owner

Choose a reason for hiding this comment

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

Why were these two setters added?

Copy link
Author

Choose a reason for hiding this comment

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

I had added them to help with modification of existing Accounts in cache (were being called from AccountInfoMap::updateAccounts()) . But, based on the java docs, it looks like Account and Container classes are supposed to be treated as immutable objects. Changed code to use AccountBuilder to re-build new Account objects while updating accounts.

try {
createMySqlAccountStore();
} catch (SQLException e) {
logger.error("MySQL account store creation failed", e);
Copy link
Owner

Choose a reason for hiding this comment

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

This is okay for now. We will need to distinguish between transient connection error and something like credential issue which should fail startup.

Copy link
Author

Choose a reason for hiding this comment

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

Sure, added a todo here.

* Sets the last modified time of accounts and containers in this in-memory cache
* @param lastModifiedTime time when the accounts and containers were last updated
*/
void setLastModifiedTime(long lastModifiedTime) {
Copy link
Owner

Choose a reason for hiding this comment

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

Where is this called?

Copy link
Author

Choose a reason for hiding this comment

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

This will be called from MySqlAccountService::fetchAndUpdateCache(). Want to set it to max LMT value found in fetched accounts and containers.


// Fetch all added/modified containers from MySql database since LMT
List<Container> containers = mySqlAccountStore.getNewContainers(lastModifiedTime);
rwLock.writeLock().lock();
Copy link
Owner

Choose a reason for hiding this comment

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

I would recommend holding the lock for both account and container update, to make sure consumers see a consistent view of the cache.

Copy link
Author

Choose a reason for hiding this comment

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

Sure, yeah true. Made changes to hold the lock for both account and container updates.

1. Address Rob's comments
2. Scheduler thread to sync changes from DB
3. Add MySqlAccountServiceFactory and MySqlAccountServiceConfig
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.

2 participants