当前位置:网站首页>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;
}边栏推荐
- [deep learning][pytorch][original]crnn trains loss on the higher version of pytorch as a solution for Nan
- 2D 照片变身 3D 模型,来看英伟达的 AI 新“魔法”!
- PPT绘图相关,快捷键,美观度
- "Write once, run at all ends", Qualcomm released AI software stack!
- A fault record of misoperation dhclient script
- H5 video conference, camera monitoring, web streaming and live broadcast integration scheme
- Shape change loader loads jsjs special effect code
- 程序员大部分时间不是写代码,而是。。。
- [latest in the whole network] how to start the opentsdb source code in the local ide run
- PHP短信通知+语音播报自动双呼
猜你喜欢

2D 照片变身 3D 模型,来看英伟达的 AI 新“魔法”!

Shape change loader loads jsjs special effect code

TP-LINK 1208 router tutorial (2)

初识string+简单用法(一)

Visual presentation of pictures effectively enhances the attraction of large screen

齐次坐标的理解

工具及方法 - 在Source Insight中使用代码格式化工具

Today's sleep quality record 76 points

Act as you like

把腾讯搬到云上,治愈了他们的技术焦虑
随机推荐
System design: key features of distributed systems
How to open a video number?
How to use data analysis tools to deal with emergencies in retail industry
[Qianfan 618 countdown!] IAAs operation and maintenance special preferential activities
What is wireless WiFi? What are the benefits of wireless WiFi
Why choose b+ tree as storage engine index structure
How to improve the quality of Baidu keyword?
使用Process Monitor工具监测进程对注册表和文件的操作
Moving Tencent to the cloud cured their technical anxiety
喜歡就去行動
Canvas falling ball gravity JS special effect animation
TP-LINK 1208 router tutorial (2)
Visual presentation of pictures effectively enhances the attraction of large screen
It's so difficult for me. Have you met these interview questions?
Cook a delicious cli
How to export only the titles in word documents? (i.e. delete all the text contents and keep only the title) stop B
Attribute observer didset and willset in swift of swiftui swift internal skill
Many of my friends asked me what books and online classes I recommended. This time, I contributed all the materials that I had been hiding for a long time (Part 1)
Ppt drawing related, shortcut keys, aesthetics
Why should we make the best use of the external chain in SEO?