TDDL 原始碼分析

2021-07-15 04:09:37 字數 3069 閱讀 9026

tddl位於資料庫和持久層之間,它直接與資料庫建立交道

tddl其實主要可以劃分為3層架構,分別是matrix層、group層和atom層。matrix層用於實現分庫分表邏輯,底層持有多個group例項。而group層和atom共同組成了動態資料來源,group層實現了資料庫的master/salve模式的寫分離邏輯,底層持有多個atom例項。最後atom層(tatomdatasource)實現資料庫ip,port,password,connectionproperties等資訊的動態推送,以及持有原子的資料來源分離的jboss資料來源。

datasource 介面:

public

inte***ce

datasource

extends

// 返回連線給jdbctemplate使用

connection getconnection() throws sqlexception;

connection getconnection(string username, string password)

throws sqlexception;

}

abstracttatomdatasource 抽象類:

public

abstract

class

abstracttatomdatasource

implements

datasource

public connection getconnection(string username, string password) throws sqlexception

public printwriter getlogwriter() throws sqlexception

public

intgetlogintimeout() throws sqlexception

public

void

setlogwriter(printwriter out) throws sqlexception

public

static

void

setshutdownmbean(boolean shutdownmbean)

public

void

setlogintimeout(int seconds) throws sqlexception

@suppresswarnings("unchecked")

public

t unwrap(classiface) throws sqlexception

else

}public

boolean

public

static

void

main(string args) throws sqlexception

}

datasource主要提供資料庫的連線、重新整理和關閉等操作的實現

public

class

tatomdatasource

extends

abstracttatomdatasource

tatomdsconfhandle 原始碼分析:

class tatomdsconfhandle
dbconfmanager 實現類 diamonddbconfmanager

public

class

diamonddbconfmanager

implements

dbconfmanager

...}

configdatahandler 實現類:

public

class

diamondconfigdatahandler

implements

configdatahandler

if (data != null) else }}

public executor getexecutor()

});string group = (string) config.get("group");

if (null != group)

this.diamondmanager = builder.build();

this.dataid = dataid;

tddlmbeanserver.registermbeanwithid(mbean, mbeanid);

}

tgroupdatasource 原始碼分析:

public

class

tgroupdatasource

implements

datasource

datasourcefetcher 介面:

public

inte***ce datasourcefetcher

datasourcefetcher 的2個實現類:

1.

private

class

mydatasourcefetcher

implements

datasourcefetcher else else }}

@override

public dbtype getdatasourcedbtype(string key)

};

2.

public

class

springdatasourcefetcher

implements

private dbtype dbtype = dbtype.mysql;

// 通過spring進行獲取

@override

public datasource getdatasource(string key)

...}

spring原始碼分析 spring原始碼分析

1.spring 執行原理 spring 啟動時讀取應用程式提供的 bean 配置資訊,並在 spring 容器中生成乙份相應的 bean 配置登錄檔,然後根據這張登錄檔例項化 bean,裝配好 bean 之間的依賴關係,為上 層應用提供準備就緒的執行環境。二 spring 原始碼分析 1.1spr...

思科VPP原始碼分析(dpo機制原始碼分析)

vpp的dpo機制跟路由緊密結合在一起。路由表查詢 ip4 lookup 的最後結果是乙個load balance t結構。該結構可以看做是乙個hash表,裡面包含了很多dpo,指向為下一步處理動作。每個dpo都是新增路由時的乙個path的結果。dpo標準型別有 dpo drop,dpo ip nu...

redux原始碼分析(三) 原始碼部分

下面是每個部分的一些解讀 createstore apicreatestore reducer,initialstate enhancer 曾經非常好奇這個函式的第二個引數到底是initialstate還是enhancer,因為見過兩種寫法都有的,以為是版本問題。看了原始碼才發現,都可以的。如果你不...