API Server Etcd

This article has studied the source code of the ETCD part, equipped with the source code for further understanding, which can deepen the understanding and enhance related design capabilities.

Hello everyone, this time I bring you ETCD source code reading. The three parts of this article are the Server part, the Storage part, and the Utility part. With the source code for further understanding, you can deepen your understanding and enhance related design capabilities.

Server

Single

Landscape

Clients contain the address to be monitored by the etcd server. The address can be in the form of TCP or Unix Socket and supports http and https. The serverCtx matches a net.Listener and runs independently of a goroutine.

Serve Procedure

Backend

Landscape

Storage

BoltDB Backend

Landscape

run

Start Timer regularly submits or submit and exit when receiving the stop signal. The code is simple, as shown below.

func (b *backend) run() {
    defer close(b.donec)
    t := time.NewTimer(b.batchInterval)
    defer t.Stop()
    for {
        select {
        case <-t.C:
        case <-b.stopc:
            b.batchTx.CommitAndStop()
            return
        }
        b.batchTx.Commit()
        t.Reset(b.batchInterval)
    }
}

Transaction Relationship

Buffer

MVCC

Store

References

Watchable

Landscape

Watcher Creation

Nofity Waiter

Utility

CMux

  • soheilhy/cmux: Connection multiplexer for GoLang: serve different services on the same port!

Landscape

Implementation

Scheduler

Landscape

WAL

Landscape

Last updated