亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Apache Omid TSO 組件源碼實(shí)現(xiàn)原理解析

 更新時(shí)間:2024年07月22日 10:41:16   作者:FlyingZCC  
這篇文章主要介紹了Apache Omid TSO 組件源碼實(shí)現(xiàn)原理解析,本文給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧

Apache Omid TSO 組件實(shí)現(xiàn)原理

作用

獨(dú)立進(jìn)程,處理全局事務(wù)之間的并發(fā)沖突。

流程

TSOChannelHandler#channelRead -> AbstractRequestProcessor -> PersistenceProcessorHandler

總體流程

thread1
    TSOChannelHandler#channelRead
        AbstractRequestProcessor#timestampRequest 接收 client 請(qǐng)求,創(chuàng)建 RequestEvent 并 publish
thread2
    AbstractRequestProcessor#onEvent 處理 RequestEvent 請(qǐng)求
        AbstractRequestProcessor#handleRequest
            PersistenceProcessorImpl#addTimestampToBatch 創(chuàng)建 PersistEvent,當(dāng) batch 滿了發(fā)送事件
thread3
    PersistenceProcessorHandler#onEvent 持久化事件處理

TSOChannelHandler

繼承自 Netty 的 ChannelInboundHandlerAdapter,用于處理 TSO 的入站請(qǐng)求。

channelRead

委托 requestProcessor 創(chuàng)建 timestampRequest 和 commitRequest 請(qǐng)求事件。

AbstractRequestProcessor

處理 timestamp 和 commit 事件。

onEvent

處理 RequestEvent 事件,按照事件類型派發(fā)給 handleTimestamp 和 handleCommit 方法進(jìn)行處理。

handleTimestamp

1.通過 timestampOracle 獲取下一個(gè)時(shí)間戳;
2.PersistenceProcessorImpl#addBatch 事件添加到 batch,但是后續(xù)對(duì) timestamp 請(qǐng)求不會(huì)額外處理。

handleCommit

主要通過 hasConflictsWithCommittedTransactions 判斷 writeSet 和 CommitHashMap 里是否有事務(wù)寫沖突,如果沒有則可以提交事務(wù),分配 commitTimestamp。

private void handleCommit(RequestEvent event) throws Exception {
    long startTimestamp = event.getStartTimestamp(); // startTimestamp
    Iterable<Long> writeSet = event.writeSet(); // 寫入集,存儲(chǔ)的是 cellIds
    Collection<Long> tableIdSet = event.getTableIdSet();
    boolean isCommitRetry = event.isCommitRetry();
    boolean nonEmptyWriteSet = writeSet.iterator().hasNext(); // 檢查寫集合是否為空,即事務(wù)是否有寫操作
    if (startTimestamp > lowWatermark &&
        !hasConflictsWithFences(startTimestamp, tableIdSet) &&
        !hasConflictsWithCommittedTransactions(startTimestamp, writeSet)) { // 檢查事務(wù)是否滿足提交條件,通過 hasConflictsWithCommittedTransactions 判斷是否有事務(wù)寫沖突
        // 可以進(jìn)行事務(wù)提交
        long commitTimestamp = timestampOracle.next(); // 獲取提交時(shí)間戳
        Optional<Long> forwardNewWaterMark = Optional.absent();
        if (nonEmptyWriteSet) { // 寫集合非空
            long newLowWatermark = lowWatermark;
            for (long r : writeSet) { // 遍歷寫集合中的每個(gè)元素,更新其最新的寫入時(shí)間戳,并計(jì)算新的低水位線
                long removed = hashmap.putLatestWriteForCell(r, commitTimestamp); // 更新 cellId 對(duì)應(yīng)的 commitTimestamp, 返回之前的 oldest commitTimestamp
                newLowWatermark = Math.max(removed, newLowWatermark); // 更新低水位線
            }
            if (newLowWatermark != lowWatermark) { // 更新低水位線
                lowWatermark = newLowWatermark;
                forwardNewWaterMark = Optional.of(lowWatermark);
            }
        }
        forwardCommit(startTimestamp, commitTimestamp, c, event.getMonCtx(), forwardNewWaterMark);  // 持久化 commit 請(qǐng)求
    } else { // 事務(wù)不滿足提交條件
        if (isCommitRetry) { // Re-check if it was already committed but the client retried due to a lag replying
            forwardCommitRetry(startTimestamp, c, event.getMonCtx());  // 若是提交重試,再次檢查是否已提交以避免因響應(yīng)延遲導(dǎo)致的重復(fù)提交
        } else {
            forwardAbort(startTimestamp, c, event.getMonCtx()); // 否則,中止事務(wù)
        }
    }
}

CommitHashMap

通過 LongCache 緩存 cellId -> lastCommittedTimestamp 的映射。

getLatestWriteForCell 方法:
根據(jù) cellId 獲取 lastCommittedTimestamp。

putLatestWriteForCell 方法:
更新 cellId 對(duì)應(yīng)的 lastCommittedTimestamp。

LongCache

緩存 cellId -> lastCommittedTimestamp 的映射。

get 和 set 操作都是先將原始 cellId 進(jìn)行 hash 操作找到位置,所以可能存在沖突。

set

更新 cellId 對(duì)應(yīng)的 lastCommittedTimestamp。

public long set(long key, long value) {
    final int index = index(key); // cellId 取模返回下標(biāo),可能會(huì)沖突
    int oldestIndex = 0;
    long oldestValue = Long.MAX_VALUE;
    for (int i = 0; i < associativity; ++i) {
        int currIndex = 2 * (index + i); // 計(jì)算 key 下標(biāo)
        if (cache[currIndex] == key) { // 相同事務(wù) cellId, 替換場(chǎng)景
            oldestValue = 0;
            oldestIndex = currIndex;
            break;
        }
        if (cache[currIndex + 1] <= oldestValue) { // 沒找到相同的key.通過和 oldestValue 比較會(huì)將最小的 timestamp 剔除
            oldestValue = cache[currIndex + 1];
            oldestIndex = currIndex;
        }
    }
    // 替換最舊的鍵值對(duì),將其更新為新的鍵值對(duì)
    cache[oldestIndex] = key;
    cache[oldestIndex + 1] = value;
    return oldestValue;
}

get

獲取 cellId 對(duì)應(yīng)的 lastCommittedTimestamp,找不到則返回 0.

public long get(long key) {
    final int index = index(key);
    for (int i = 0; i < associativity; ++i) { // associativity 里存儲(chǔ)的元素key應(yīng)該是相同的
        int currIndex = 2 * (index + i); // 計(jì)算 key 的下標(biāo)
        if (cache[currIndex] == key) { // 找到 cache key
            return cache[currIndex + 1]; // 返回對(duì)應(yīng)的 value
        }
    }
    return 0;
}

PersistenceProcessorImpl

將 startTimestamp 和 commitTimestamp 放入 batch.

addCommitToBatch

創(chuàng)建 event,添加到 current batch
如果 current batch is full
    triggerCurrentBatchFlush

triggerCurrentBatchFlush

創(chuàng)建 PersistBatchEvent 并發(fā)送事件

PersistenceProcessorHandler

處理上面 PersistenceProcessorImpl 發(fā)送過來的事件,進(jìn)行持久化處理。

onEvent

實(shí)際上只處理 commit 事件,會(huì)創(chuàng)建 put 對(duì)象將事務(wù)信息持久化到 hbase 的 commitTable (OMID_COMMIT_TABLE).

HBaseCommitTable

構(gòu)造方法: 根據(jù) HBaseCommitTableConfig 配置初始化

到此這篇關(guān)于Apache Omid TSO 組件源碼實(shí)現(xiàn)原理的文章就介紹到這了,更多相關(guān)Apache Omid TSO 組件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • ubuntu下的虛擬環(huán)境中安裝Django的操作方法

    ubuntu下的虛擬環(huán)境中安裝Django的操作方法

    這篇文章主要介紹了ubuntu下的虛擬環(huán)境中安裝Django的操作方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-09-09
  • CentOS系統(tǒng)Maven安裝教程分享

    CentOS系統(tǒng)Maven安裝教程分享

    本文介紹了如何在CentOS系統(tǒng)中安裝Maven,并提供了一個(gè)簡(jiǎn)單的實(shí)際應(yīng)用案例,安裝Maven需要先安裝Java和設(shè)置環(huán)境變量,Maven可以自動(dòng)管理項(xiàng)目的構(gòu)建、報(bào)告和文檔
    2025-02-02
  • Linux+php+apache+oracle環(huán)境搭建之CentOS下安裝Oracle數(shù)據(jù)庫

    Linux+php+apache+oracle環(huán)境搭建之CentOS下安裝Oracle數(shù)據(jù)庫

    研究了兩天Linux下安裝Oracle,重裝了兩次虛擬機(jī),終于安裝成功。很有收獲的。記錄下安裝過程。大神們?nèi)缬懈玫姆绞?,?qǐng)聯(lián)系我!
    2014-08-08
  • 在 Linux 上使用 Multitail命令的教程

    在 Linux 上使用 Multitail命令的教程

    MultiTail是一個(gè)開源的ncurses的實(shí)用工具,可用于在一個(gè)窗口或單一外殼,顯示實(shí)時(shí)一樣的尾巴命令,該命令拆分控制臺(tái)為更多子窗口的日志文件的最后幾行。這篇文章主要介紹了在 Linux 上使用 Multitail命令的教程,需要的朋友可以參考下
    2019-12-12
  • 詳解git中配置的.gitignore不生效的解決辦法

    詳解git中配置的.gitignore不生效的解決辦法

    這篇文章主要介紹了詳解git中配置的.gitignore不生效的解決辦法的相關(guān)資料,這里提供解決辦法希望能幫助到大家,需要的朋友可以參考下
    2017-09-09
  • Linux proc目錄下子文件或子文件夾的作用

    Linux proc目錄下子文件或子文件夾的作用

    這篇文章主要介紹了Linux proc目錄下子文件或子文件夾的作用,以及讀取這些信息的實(shí)際操作命令,需要的朋友可以參考下
    2014-03-03
  • DDNS 的工作原理及其在 Linux 上的實(shí)現(xiàn)

    DDNS 的工作原理及其在 Linux 上的實(shí)現(xiàn)

    DDNS (Dynamic DNS) 擴(kuò)展了 DNS 將客戶端 IP 與其域名進(jìn)行靜態(tài)映射的功能,它可以將同一域名實(shí)時(shí)地解析為不同的動(dòng)態(tài) IP,而不需要額外的人工干預(yù)
    2016-09-09
  • linux兩臺(tái)服務(wù)器實(shí)現(xiàn)自動(dòng)同步文件

    linux兩臺(tái)服務(wù)器實(shí)現(xiàn)自動(dòng)同步文件

    這篇文章主要介紹了linux兩臺(tái)服務(wù)器實(shí)現(xiàn)自動(dòng)同步文件,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-08-08
  • Linux命令行快速技巧之定位一個(gè)文件的方法

    Linux命令行快速技巧之定位一個(gè)文件的方法

    Linux 命令行專門設(shè)計(jì)了很多非常有用的命令行工具在你的電腦上查找文件。下面我們看一下它們其中三個(gè):ls、tree 和 find。 感興趣的朋友跟隨小編一起看看吧
    2018-11-11
  • Linux下activeMQ的啟動(dòng)和停止命令方式

    Linux下activeMQ的啟動(dòng)和停止命令方式

    文章介紹了在Linux環(huán)境下啟動(dòng)和停止Apache ActiveMQ的步驟,啟動(dòng)前需要確保服務(wù)未運(yùn)行,使用`./activemq start`命令啟動(dòng),停止時(shí)使用`./activemq stop`命令,啟動(dòng)后可以通過訪問`http://127.0.0.1:8161/admin/`來驗(yàn)證服務(wù)是否成功啟動(dòng)
    2024-12-12

最新評(píng)論