Class MySqlAccountService

  • All Implemented Interfaces:
    com.github.ambry.account.AccountService, java.io.Closeable, java.lang.AutoCloseable

    public class MySqlAccountService
    extends java.lang.Object
    An implementation of AccountService that employs MySql database as its underlying storage.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.concurrent.atomic.AtomicReference<com.github.ambry.account.AccountInfoMap> accountInfoMapRef  
      protected AccountServiceMetrics accountServiceMetrics  
      protected java.util.concurrent.CopyOnWriteArraySet<java.util.function.Consumer<java.util.Collection<com.github.ambry.account.Account>>> accountUpdateConsumers  
      protected java.util.concurrent.locks.ReentrantLock lock  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean addAccountUpdateConsumer​(java.util.function.Consumer<java.util.Collection<com.github.ambry.account.Account>> accountUpdateConsumer)  
      protected void checkOpen()
      Ensures the account service is ready to process requests.
      void close()  
      com.github.ambry.account.Account getAccountById​(short accountId)  
      com.github.ambry.account.Account getAccountByName​(java.lang.String accountName)  
      java.util.Collection<com.github.ambry.account.Account> getAllAccounts()  
      protected void notifyAccountUpdateConsumers​(com.github.ambry.account.AccountInfoMap newAccountInfoMap, com.github.ambry.account.AccountInfoMap oldAccountInfoMap, boolean isCalledFromListener)
      Logs and notifies account update Consumers about any new account changes/creations.
      boolean removeAccountUpdateConsumer​(java.util.function.Consumer<java.util.Collection<com.github.ambry.account.Account>> accountUpdateConsumer)  
      void selectInactiveContainersAndMarkInZK​(com.github.ambry.server.StatsSnapshot statsSnapshot)  
      boolean updateAccounts​(java.util.Collection<com.github.ambry.account.Account> accounts)  
      java.util.Collection<com.github.ambry.account.Container> updateContainers​(java.lang.String accountName, java.util.Collection<com.github.ambry.account.Container> containers)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface com.github.ambry.account.AccountService

        getContainer, getContainersByStatus
    • Field Detail

      • accountInfoMapRef

        protected final java.util.concurrent.atomic.AtomicReference<com.github.ambry.account.AccountInfoMap> accountInfoMapRef
      • lock

        protected final java.util.concurrent.locks.ReentrantLock lock
      • accountUpdateConsumers

        protected final java.util.concurrent.CopyOnWriteArraySet<java.util.function.Consumer<java.util.Collection<com.github.ambry.account.Account>>> accountUpdateConsumers
    • Constructor Detail

      • MySqlAccountService

        public MySqlAccountService​(AccountServiceMetrics accountServiceMetrics,
                                   com.github.ambry.config.MySqlAccountServiceConfig config,
                                   MySqlAccountStoreFactory mySqlAccountStoreFactory)
                            throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • getAccountById

        public com.github.ambry.account.Account getAccountById​(short accountId)
        Specified by:
        getAccountById in interface com.github.ambry.account.AccountService
      • getAccountByName

        public com.github.ambry.account.Account getAccountByName​(java.lang.String accountName)
        Specified by:
        getAccountByName in interface com.github.ambry.account.AccountService
      • updateAccounts

        public boolean updateAccounts​(java.util.Collection<com.github.ambry.account.Account> accounts)
      • getAllAccounts

        public java.util.Collection<com.github.ambry.account.Account> getAllAccounts()
        Specified by:
        getAllAccounts in interface com.github.ambry.account.AccountService
      • addAccountUpdateConsumer

        public boolean addAccountUpdateConsumer​(java.util.function.Consumer<java.util.Collection<com.github.ambry.account.Account>> accountUpdateConsumer)
        Specified by:
        addAccountUpdateConsumer in interface com.github.ambry.account.AccountService
      • removeAccountUpdateConsumer

        public boolean removeAccountUpdateConsumer​(java.util.function.Consumer<java.util.Collection<com.github.ambry.account.Account>> accountUpdateConsumer)
        Specified by:
        removeAccountUpdateConsumer in interface com.github.ambry.account.AccountService
      • selectInactiveContainersAndMarkInZK

        public void selectInactiveContainersAndMarkInZK​(com.github.ambry.server.StatsSnapshot statsSnapshot)
      • close

        public void close()
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • checkOpen

        protected void checkOpen()
        Ensures the account service is ready to process requests. Throws an unchecked exception (for example IllegalStateException) if the account service is not ready to process requests.
      • updateContainers

        public java.util.Collection<com.github.ambry.account.Container> updateContainers​(java.lang.String accountName,
                                                                                         java.util.Collection<com.github.ambry.account.Container> containers)
                                                                                  throws com.github.ambry.account.AccountServiceException
        Specified by:
        updateContainers in interface com.github.ambry.account.AccountService
        Throws:
        com.github.ambry.account.AccountServiceException
      • notifyAccountUpdateConsumers

        protected void notifyAccountUpdateConsumers​(com.github.ambry.account.AccountInfoMap newAccountInfoMap,
                                                    com.github.ambry.account.AccountInfoMap oldAccountInfoMap,
                                                    boolean isCalledFromListener)
        Logs and notifies account update Consumers about any new account changes/creations.
        Parameters:
        newAccountInfoMap - the new AccountInfoMap that has been set.
        oldAccountInfoMap - the AccountInfoMap that was cached before this change.
        isCalledFromListener - true if the caller is the account update listener, {@@code false} otherwise.