西维蜀黍

【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
  ...