高度分布式OLTP架构


不想吃东西
2025-03-18 08:38:24 (14天前)
  1. 是否有一个已知的高度建筑解决方案


分散式
</跨度>
适用前置条件的OLTP情况?例如,让我们使用银行示例。 A人想要将$ N转移给B人。这个成功的前提条件是A人的A必须超过$ N.

帐户
</跨度>

从人员A的角度来看,他们登录到一些Web应用程序。他们从create创建转移

4 条回复
  1. 0# 晴天?霹雳 | 2019-08-31 10-32



    你看过Splice Machine了吗?它是一个完全符合ACID标准的RDBMS,它运行在hadoop堆栈(hbase,spark,hdfs,zookeeper)之上。它们具有双体系结构,使用hbase进行快速OLTP查询,并为OLAP查询提供内容,并且内置了不需要任何锁定的事务功能。


  2. 1# 晴天3 | 2019-08-31 10-32



    基本上你需要的是一个分布式锁定机制。许多分布式服务器应用程序提供了这样的功能。



    基本上,如果我们将您的问题转换为代码,它将看起来像这样




    1. // BANK WITHDRAWAL APPLICATION

    2. // Fetch BankAccount object from NCache
      BankAccount account = cache.Get(“Key”) as BankAccount; // balance = 30,000
      Money withdrawAmount = 15000;

    3. if (account != null && account.IsActive)
      {
      // Withdraw money and reduce the balance
      account.Balance -= withdrawAmount;

    4. // Update cache with new balance = 15,000
    5. cache.Insert("Key", account);
    6. }

    7. </code>




    1. // BANK DEPOSIT APPLICATION

    2. // Fetch BankAccount object from NCache
      BankAccount account = cache.Get(“Key”) as BankAccount; // balance = 30,000
      Money depositAmount = 5000;

    3. if (account != null && account.IsActive)
      {
      // Deposit money and increment the balance
      account.Balance += depositAmount;

    4. // Update cache with new balance = 35,000
    5. cache.Insert("Key", account); 
    6. }

    7. </code>


    这基本上是竞争条件的一个例子




    竞争条件是两个或更多用户同时尝试访问和更改相同的共享数据,但最终以错误的顺序执行此操作。




    分布式锁定中上述代码的答案是




    1. LockHandle lockHandle = new LockHandle();

    2. // Specify time span of 10 sec for which the item remains locked
      // NCache will auto release the lock after 10 seconds.
      TimeSpan lockSpan = new TimeSpan(0, 0, 10);

    3. try
      {
      // If item fetch is successful, lockHandle object will be populated
      // The lockHandle object will be used to unlock the cache item
      // acquireLock should be true if you want to acquire to the lock.
      // If item does not exists, account will be null
      BankAccount account = cache.Get(key, lockSpan,
      ref lockHandle, acquireLock) as BankAccount;
      // Lock acquired otherwise it will throw LockingException exception

    4. if(account != null && account.IsActive)
    5. {
    6.     // Withdraw money or Deposit
    7.     account.Balance += withdrawAmount;
    8.     // account.Balance -= depositAmount;
    9.     // Insert the data in the cache and release the lock simultaneously 
    10.     // LockHandle initially used to lock the item must be provided
    11.     // releaseLock should be true to release the lock, otherwise false
    12.     cache.Insert("Key", account, lockHandle, releaseLock); 
    13. }
    14. else
    15. {
    16.     // Either does not exist or unable to cast
    17.     // Explicitly release the lock in case of errors
    18.     cache.Unlock("Key", lockHandle);
    19. } 
    20. }
      catch(LockingException lockException)
      {
      // Lock couldn’t be acquired
      // Wait and try again
      }

    21. </code>


    这个答案非常特定于NCache(分布式缓存)。我相信你会在关键字“分布式锁定”下找到更多解决方案




    资源


  3. 2# Jacob | 2019-08-31 10-32



    ClustrixDB是另一种可能值得一试的解决方案。它使用Paxos进行分布式事务解析(内置于分布式,ACID,SQL兼容的RDBMS),并具有内置的容错功能。


登录 后才能参与评论