西维蜀黍

【Architectural Pattern】Publish/Subscribe Pattern

Definition

In software architecture, publish–subscribe pattern is a messaging pattern where senders of messages, called publishers, do not program the messages to be sent directly to specific receivers, called subscribers, but instead categorize published messages into classes without knowledge of which subscribers, if any, there may be. Similarly, subscribers express interest in one or more classes and only receive messages that are of interest, without knowledge of which publishers, if any, there are.

Publish–subscribe is a sibling of the message queue paradigm, and is typically one part of a larger message-oriented middleware system. Most messaging systems support both the pub/sub and message queue models in their API, e.g. Java Message Service (JMS).

This pattern provides greater network scalability and a more dynamic network topology, with a resulting decreased flexibility to modify the publisher and the structure of the published data.

  ...


【Distributed System】Message Oriented Middleware

Message Oriented Middleware (MOM)

Message Oriented Middleware is a concept that involves the passing of data between applications using a communication channel that carries self-contained units of information (messages).

Note that since the message broker is the most component in a Message Oriented Middleware, therefore, message broker sometimes is used with Message Oriented Middleware interchangeably.

  ...


【Database】事务(Transactions)

Basic Idea

A transaction is an executing program that forms a logical unit of database processing.

A transaction includes one or more database access operations—these can include insertion, deletion, modification (update), or retrieval operations.

The database operations that form a transaction can either be embedded within an application program or they can be specified interactively via a high-level query language such as SQL.

  ...


【MySQL】MySQL中有的锁(Lock)

MySQL 中的锁

  • 全局锁
  • 表级锁
    • 表锁 table locks
    • AUTO-INC 锁
    • 元数据锁 Metadata lock
    • 意向锁 Intention Locks
  • 行级锁
    • 记录锁 Record Lock:也就是仅仅把一条记录锁上
    • 间隙锁 Gap Lock:锁定一个范围,但是不包含记录本身
    • Next-Key Lock:Record Lock + Gap Lock 的组合,锁定一个范围,并且锁定记录本身
  ...


【MySQL】Insert and Update

Situation

Often you have the situation that you need to check if an table entry exists, before you can make an update. If it does not exist, you have to do an insert first.

The simple straightforward approach is this:

(The example is for an entry in the WordPress wp_postmeta table)
SELECT meta_id FROM wp_postmeta
WHERE post_id = ?id AND meta_key = ‘page_title’

If ResultCount == 0

INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
VALUES (?id, ‘page_title’, ?page_title)

Else

UPDATE wp_postmeta SET meta_value = ?page_title
WHERE post_id = ?id AND meta_key = ‘page_title’
  ...


【Linux】命令 - df

Usage

# Display all filesystems and their disk usage:
$ df

# Display all filesystems and their disk usage in human readable form:
$ df -h

# Display the filesystem and its disk usage containing the given file or directory:
$ df path/to/file_or_directory

# Display statistics on the number of free inodes:
$ df -i

# Display filesystems but exclude the specified types:
$ df -x squashfs -x tmpfs
  ...


【Linux】命令 - stat

Usage

# Show file properties such as size, permissions, creation and access dates among others:
$ stat file

# Same as above but verbose (more similar to linux's stat):
$ stat -x file

# Show only octal file permissions:
$ stat -f %Mp%Lp file

# Show owner and group of the file:
$ stat -f "%Su %Sg" file

# Show the size of the file in bytes:
$ stat -f "%z %N" file
  ...


【Linux】命令 - du

du Command

du command, short for disk usage, is used to estimate file space usage.

The du command can be used to track the files and directories which are consuming excessive amount of space on hard disk drive.

  ...


【Linux】File Systems

Demo

# Create a 10G big file
$ fallocate -l 10G 10g_file.img

$ mkdir sw_test

$ time cp 10g_file.img sw_test/
cp 10g_file.img sw_test/  0.08s user 8.18s system 97% cpu 8.459 total

$ du -h 10g_file.img
11G	10g_file.img

$ du -h sw_test
11G	sw_test

$ stat 10g_file.img
  File: 10g_file.img
  Size: 10737418240	Blocks: 20971528   IO Block: 4096   regular file
Device: fd00h/64768d	Inode: 524359      Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/      sw)   Gid: ( 1000/      sw)
Access: 2021-10-20 00:05:29.925335381 +0800
Modify: 2021-10-20 00:04:17.067027796 +0800
Change: 2021-10-20 00:04:17.067027796 +0800
 Birth: -
$ stat sw_test/10g_file.img
  File: sw_test/10g_file.img
  Size: 10737418240	Blocks: 20971528   IO Block: 4096   regular file
Device: fd00h/64768d	Inode: 2228230     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/      sw)   Gid: ( 1000/      sw)
Access: 2021-10-20 00:05:29.925335381 +0800
Modify: 2021-10-20 00:05:58.946511217 +0800
Change: 2021-10-20 00:05:58.946511217 +0800
  ...


【Linux】磁盘空间不足 - 扩容

Context

使用 Docker 拉取 MySQL 镜像时发现磁盘空间不够:no space left on device

root@ubuntu:~# docker pull mysql:5.7.29
5.7.29: Pulling from library/mysql
68ced04f60ab: Pull complete 
f9748e016a5c: Pull complete 
da54b038fed1: Pull complete 
6895ec5eb2c0: Pull complete 
111ba0647b87: Pull complete 
c1dce60f2f1a: Pull complete 
702ec598d0af: Pull complete 
63cca87a5d4d: Pull complete 
ec05b7b1c5c7: Extracting [==================================================>]  112.2MB/112.2MB
834b1d9f49b0: Download complete 
8ded6a30c87c: Download complete 
failed to register layer: Error processing tar file(exit status 1): write /usr/sbin/mysqld: no space left on device
  ...