当前位置:网站首页>Nacos source code - Interface read configuration
Nacos source code - Interface read configuration
2022-06-24 11:16:00 【prepared】
Read configuration process
1、 The entrance ConfigController::getConfig() In the method ;
2、 Get read lock , If successful , Go to the next step , Otherwise return to failure ( Less than indicates writing ( Write lock ), be equal to 0 Indicates that there is no configuration data , Because the read lock can be acquired repeatedly );
3、 according to groupKey Get the basic information in the cache (isBeta,configType Etc );
4、 According to the deployment mode ( whether standalone)、 Whether the database used is a built-in database derby, To determine whether to read the database or the file ;
5、 Return to content Information ( If it is to check the database ), Or file stream content .
Something to watch out for
1、 If it is standalone Deploy , And it uses a built-in database derby, Directly query the data in the database ,cache(ConcurrentHashMap); otherwise , Read nacos File system (nacos/distribution/target/nacos-server-${version}/nacos/data/config-data/${GROUP_NAME}/${dataId}) The data of .
2、 Before getting the configuration , Need to get == Read the lock ==
3、 adopt ConcurrentHashMap Cache the basic information of the configuration file , Include :groupKey,md5,lastModifiedTs
// Determines whether to read the data directly
// if use mysql, Reduce database read pressure
// if use raft+derby, Reduce leader read pressure
public static boolean isDirectRead() {
return EnvUtil.getStandaloneMode() && isEmbeddedStorage();
}Why? nacos Get offline , You can also get the configuration ?
Because when the service starts , Will visit the registry nacos, Update the configuration to the environment variable , Can open endpoints
management.endpoints.web.exposure.include=* management.endpoint.health.show-details=always
And then visit :http://localhost:8080/actuator/env, You can view the configuration data in the environment variable .
What is worth learning
The realization of read-write lock
There is no particularly profound content , Use synchronized Keyword decorated to acquire lock 、 Method of releasing the lock .
Read locks can be acquired multiple times , adopt int Type of status Incrementally implement multiple lock reads ;
Only one write lock , Mark status by -1.
Be careful : The lock needs to be released manually .
/**
* Simplest read-write lock implementation. Requires locking and unlocking must be called in pairs.
*
* @author Nacos
*/
public class SimpleReadWriteLock {
/**
* Try read lock.
*/
public synchronized boolean tryReadLock() {
if (isWriteLocked()) {
return false;
} else {
status++;
return true;
}
}
/**
* Release the read lock.
*/
public synchronized void releaseReadLock() {
status--;
}
/**
* Try write lock.
*/
public synchronized boolean tryWriteLock() {
if (!isFree()) {
return false;
} else {
status = -1;
return true;
}
}
public synchronized void releaseWriteLock() {
status = 0;
}
private boolean isWriteLocked() {
return status < 0;
}
private boolean isFree() {
return status == 0;
}
/**
* Zero means no lock; Negative Numbers mean write locks; Positive Numbers mean read locks, and the numeric value
* represents the number of read locks.
*/
private int status = 0;
}边栏推荐
- SwiftUI Swift 内功之 Swift 中的属性观察者 didSet 与 willSet
- Redis
- Clickhouse deployment and basic usage 1
- Which is a good CAD drawing software? How to select good software
- Qt: 判断字符串是否为数字格式
- Step 3: access the API interface for inquiry of SF express doc No. [express 100api interface]
- 使用Process Monitor工具监测进程对注册表和文件的操作
- How to export only the titles in word documents? (i.e. delete all the text contents and keep only the title) stop B
- Preparation for a series of courses on WordPress applet generation
- Google ranging for PHP wechat development
猜你喜欢

脚本之美│VBS 入门交互实战

腾讯开源项目「应龙」成Apache顶级项目:前身长期服务微信支付,能hold住百万亿级数据流处理...

Understanding of homogeneous coordinates

初识string+简单用法(一)

Use the process monitor tool to monitor process operations on registries and files

Canvas falling ball gravity JS special effect animation

如何开发短信通知和语音功能医院信息系统(HIS系统)

“一个优秀程序员可抵五个普通程序员!”

Visual presentation of pictures effectively enhances the attraction of large screen

math_ Summation and derivation of proportional series & derivation of sum and difference of equal powers / difference between two nth power numbers/
随机推荐
Dedecms template file explanation and homepage label replacement
Nacos source code - configure automatic update
What is a compressed file? What are the advantages of different methods of compressing files?
Tencent wetest platform will bring new benefits in 2021 with 618 special offers!
【206】使用php语言去生成go语言的代码
Multi gate mixture of experts and code implementation
Nxshell session management supports import and export
[graduation season · attacking technology Er] three turns around the tree, what branch can we rely on?
Virtual CD-ROM function how to use and install virtual CD-ROM
[technical tutorial] national standard protocol platform easygbs cascading supports customized national standard channels
What is wireless WiFi? What are the benefits of wireless WiFi
Maui's way of learning -- Opening
【本周六活动】.NET Day in China
Why should we make the best use of the external chain in SEO?
The nodejs service global timeout callback failed to get process Domain problem
脚本之美│VBS 入门交互实战
I pushed my younger brother into Tencent. Look at his benchmark resume!
Code is really - omnipotent! Refuse to fight
[the lottery in May has ended, and the list of winners has been announced] special session of techo youth university open course database
Investing in a good navigation framework from the beginning of the jetpack compose tutorial will help you save a lot of migration work later