===============
== CyberJunk ==
===============
Made with 😭

Some notes on Receivers

GoLang

Review of receivers

When a value receiver is defined, Go automatically generates a corresponding pointer receiver.

Auto-generating a pointer receiver causes differences in the method sets of pointer types and value types.

For example, take the Len() method below, Go will automatically generate a corresponding pointer receiver version:

type List []int

func (l List) Len() int { return len(l) }
// func (l *List) Len() int { ... }
func (l *List) Append(val int) { *l = append(*l, val) }

For type List, its method set includes:

Read more...

Lock Based Concurrency Control Protocol

Database

“Lock-Based Concurrency Control” and “Multiversion Concurrency Control” are two different approaches to implementing transaction isolation levels. This article will introduce the former one.

In two-phase locking, a transaction is divided into the growing phase for acquiring locks and the shrinking phase for releasing locks. Different rules and restrictions can be set in different phases to achieve different isolation levels. For example:

  1. Do you need a lock to read? What type of lock is needed to read?
  2. When to unlock?

When writing data, transactions at all isolation levels always require an X lock, which is unlocked at the end of the transaction. This prevents dirty writes, which are not allowed in databases, from occurring between two write transactions. Therefore, X locks may be used at all isolation levels, but S locks are not always required.

Read more...

Through an Equality Query on a Record What Locks Will Be Added

Database

In the example table, id is the primary key, create a normal index on field age, and a unique index on name.

mysql> show create table test\G;
Create Table: CREATE TABLE `test` (
  `id` int NOT NULL,
  `age` int DEFAULT NULL,
  `msg` varchar(255) DEFAULT NULL,
  `name` char(10) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`),
  KEY `idx_age` (`age`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

mysql> select * from test;  
+----+------+------+------+  
| id | age  | msg  | name |  
+----+------+------+------+  
|  1 |   10 | NULL | a    |  
|  3 |   20 | NULL | NULL |  
|  4 |   21 | NULL | NULL |  
+----+------+------+------+

Observe the locking situation under the RR level.

1. Updating records through the primary key unique index

Check the execution plan; it uses the primary index.

Read more...

Auto Generated Primary Key in MySQL

Database

When a primary key is not explicitly specified, MySQL uses the first not null, unique, and integer field as the primary key. If none are found, it generates an implicit primary key ROW_ID.

Creating the following four tables, only the last one will use id as the primary key. Since secondary indexes include the primary key, let’s create a secondary index to test and observe the indexing situation on these tables.

Read more...

Network Programming Model

OS

Blocking and Non-blocking I/O

The focus of “blocking” and “non-blocking” I/O is how user programs handle situations when data is not ready in the kernel.

Comparison of BIO and NIO

Blocking I/O (BIO)

  • When try to read, if the data is not available (e.g., no data), OS blocks and waits until data is readable.

  • When try to write, if the data cannot be written (e.g., buffer is full), OS blocks and waits until it can write.

    Read more...

Hello

default

Hello another world.

1 of 1