How to Read TiDB Source Code (Part 3)

In the previous article, we introduced methods for viewing syntax and configurations. In this article, we will discuss how to view system variables, including default values, scopes, and how to monitor metrics. System Variables The system variable names in TiDB are defined in tidb_vars.go. This file also includes some default values for variables, but the place where they are actually assembled is defaultSysVars. This large struct array defines the scope, variable names, and default values for all variables in TiDB. Besides TiDB’s own system variables, it also includes compatibility with MySQL’s system variables. ...

July 28, 2020 · 8 min · 1659 words · Jack Yu

How to Read TiDB Source Code (Part 2)

Continuing from the previous article, we learned how to set up the environment for reading code and where to start reading the code. In this part, we’ll introduce methods for viewing code based on some common needs. How to Check the Support Level of a Syntax There are usually two methods: Check through the parser repo Directly check within the TiDB repo Both of these methods require the environment setup from the previous article. If you haven’t tried that yet, give it a go. ...

July 12, 2020 · 4 min · 791 words · Jack Yu

How to Read TiDB Source Code (Part 1)

Background There are many articles on reading the source code of TiDB, often referred to as the “Twenty-Four Chapters Scriptures”. However, these introductions typically proceed from a macro to a micro perspective. This series attempts to introduce how to read TiDB’s source code from an easier angle. The goals we aim to achieve are: Enable readers to start reading TiDB’s code themselves, rather than understanding it passively through pre-written articles. Provide some common examples of looking into the details of the code, such as examining the scope of a variable. After all, teaching people to fish is better than giving them fish. While the code changes often, the methods remain mostly unchanged. ...

July 6, 2020 · 6 min · 1250 words · Jack Yu

How to Use Docker on Windows

Background I had to install Docker on Windows to reproduce a bug. Process Using Windows 10 as an example, if you have the Home Basic version, you’ll need to pay to upgrade to the Pro version because you need to enable Hyper-V and Container features, which costs about 800 RMB. Install everything with the default settings, and do not switch to Windows Containers, since most images are still under Linux. If you do switch, you can restore it after starting up. If you encounter permission issues with shared folders, follow the instructions at link. However, this might not solve the problem, and you might encounter a sharing failure. In that case, go to the settings, troubleshoot, and reset to factory defaults. After resetting, ensure the shared folders are selected. When you encounter errors during use, just try a few more times. It might work; if not, reset it. Impressions Initially, there were no issues using Docker on Linux; Docker itself was simple back then. Later, using it on Mac brought changes, including a user interface, various colors, and numerous bugs. Right from the start, I encountered bugs. Docker did not support Windows a long time ago, and given the various bugs on Mac, I didn’t have high expectations. The results were still quite surprising. In summary, here are a few points: ...

April 13, 2020 · 2 min · 269 words · Jack Yu

How to Prevent a Linux Laptop from Entering Sleep Mode When the Lid is Closed

Initially, I thought it would be a simple setting adjustment, so I casually Googled it. Sure enough, there was a unanimous solution: modify /etc/systemd/logind.conf, change HandleLidSwitch to ignore or lock, and then restart logind or reboot. I tried this, but it didn’t work at all on my Thinkpad X230. I then tried changing some other options in the aforementioned file, but none worked, and surprisingly, Ubuntu even reported errors. So, I reinstalled the more preferred Debian. Tried again, and it still didn’t work. Finally, I found a more brutal method. ...

March 31, 2020 · 1 min · 171 words · Jack Yu

How to Dynamically Update DNS Records for Namesilo

Dynamically Updating DNS Records The purpose of dynamic updates is pretty simple. As a long-term user of China Unicom’s broadband, although Unicom provides a public address, it is essentially a dynamic address, not a fixed one. If you want to access your home devices using an IP address from outside, you need to use dynamic DNS (DDNS). Many routers come with built-in DDNS functionality, but they mostly wrap the interfaces of the commonly used service providers. These providers generally have a few characteristics: 1. Blocked by the Great Firewall; 2. Not cheap; 3. Domestic providers may have security issues; 4. The company might have gone out of business. Rather than relying on these unreliable services, it’s better to write your own script for updating. ...

February 1, 2020 · 3 min · 438 words · Jack Yu

How to Start a PowerShell Script in the Background at Windows Startup

Create a script and place it in C:\Users\name\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\` Fill the script with: Start-Process -FilePath "C:\Users\name\bin\gost-windows-amd64.exe" -ArgumentList "-L=", "-F=" -RedirectStandardOutput "C:\Users\name\bin\gost-windows-amd64.log" -RedirectStandardError "C:\Users\name\bin\gost-windows-amd64.err" -WindowStyle Hidden Note: Start-Process seems to perform a fork-like action, and by default, it opens a new PowerShell window to execute. That’s why -WindowStyle Hidden is added at the end. You can’t use -NoNewWindow here because it only prevents the creation of a new window for executing Start-Process, but the old window will not exit. Note 2: After the old window exits, the forked process seems to become an orphan and is managed elsewhere, so permissions, such as network connection permissions, might need to be requested again. ...

January 14, 2020 · 1 min · 110 words · Jack Yu

How to Deploy an HTTPS Proxy Service

Preface One day, I came across an article by Chen Hao on Twitter. Having benefited from several of his blog posts, I instinctively felt it was reliable, so I read it and decided to write this practical guide. Why Use an HTTPS Proxy In the guide, it’s clearly explained why, plus my own experiences of several shadowsocks being banned, I felt it was necessary to switch to a more secure proxy method. ...

January 12, 2020 · 4 min · 737 words · Jack Yu

Using delve to Debug Golang Programs

Background When I first started writing Golang, I was always looking for a convenient debugging tool. Back then, I came across documentation about using gdb to debug and also tried delve, but neither felt easy to use. Later, on someone’s advice, I went back to the good old print statements… Over the past couple of days, I was debugging go test and found that tests would always hang when run per package. I couldn’t think of a suitable method at first, so I thought of delve again. After giving it a try, I found it has become much more mature than before. ...

September 16, 2019 · 3 min · 613 words · Jack Yu

How to Deploy a Shadowsocks Server

There are multiple versions of the Shadowsocks server side implementation. The original version was written in Python, and later, enthusiasts implemented it in various programming languages of their liking. Among all these implementations, I personally think the most reliable and stable one is the original Python version. The reason is simple - it has the most users. The Golang version is said to have the most features and also performs very well, making it quite powerful. This might be due to Golang’s inherent high performance and ease of implementation. There’s also an implementation using libev, a pure C implementation, which also offers good performance and is very lightweight. ...

September 27, 2018 · 2 min · 305 words · Jack Yu