T i l
Postgres streaming replication protocol
I have know about the postgres wire protocol, but first I ran into streaming replication protocol.
I was looking at this code in stolon
replConnParams["replication"] = "1" db, err := sql.Open("postgres", replConnParams.ConnString()) if err != nil { return nil, err } defer db.Close() rows, err := query(ctx, db, "IDENTIFY_SYSTEM") if err != nil { return nil, err } I was wondering what is this IDENTIFY_SYSTEM. A G-search pointed me to this
T i l
Named break statement in Go
I came across this piece of code from The Go Programming Language book.
loop: for { select { case size, ok := <-fileSizes: if !ok { break loop // fileSizes was closed } nfiles++ nbytes += size case <-tick: printDiskUsage(nfiles, nbytes) } } The complete program is available in Github
Named break statement allows to break perhaps multiple control statements. In this example, break loop breaks the select and for statement.
T i l
capturing iteration variables in Go
I was going through The Go Programming Language and in chapter 5 there was a section Caveat: Capturing Iteration Variables.
The example is like this:
var rmdirs []func() for _, dir := range tempDirs() { // 1 os.MkdirAll(dir, 0755) // 2 rmdirs = append(rmdirs, func() { os.RemoveAll(dir) // NOTE: incorrect! // 3 }) } dir is the same variable. i.e. the address of the variable is same dir’s value evaluated at this point is different at each iteration IMPORTANT dir is not evaluated here.
T i l
Understanding shallow copy vs deep copy in Go
In Go, copying generally does a copy by value. So modifying the destination, doesn’t modify the source. However, that holds good only if you are copying value types not reference types (i.e. pointer, slice, map etc.)
package main import ( "fmt" ) func main() { type Cat struct { age int name string Friends []string //reference type } wilson := Cat{7, "Wilson", []string{"Tom", "Tabata", "Willie"}} // shallow copy nikita := wilson // modifies both nikita and wilson nikita.
T i l
USR2 kill signal in Linux
I have used many signals with kill like SIGHUP, SIGKILL etc. Today I came across USR2.
Did a Google search and found the manual page from GNU. According to it,
These signals are used for various other purposes. In general, they will not affect your program unless it explicitly uses them for something. Another one from the BSD mailing list
USR2 is a "user defined signal" (from "man signal") It doesn't "mean" anything by definition.
T i l
IP in CIDR or not
There are tools like https://tehnoblog.org/ip-tools/ip-address-in-cidr-range/ which does the job. It doesn’t support IPv6. One of my colleagues today taught me how to do it by hand quickly.
Say we have an IP 2b06:4600:1101:0:abcd:efa:dbd:ea60:f5a6 is in the CIDR 2b06:4600:1101::/64
First step is to check what’s the mask bits. Here it is 64. So you take the address, take the first 64 bits and see if they are the same as the CIDR.