ARTS Week 1

Algorithm:

Problem: Reorder Log Files
Answer:

bool logCompare(string log1, string log2)
{
    int p1 = log1.find(' ');
    int p2 = log2.find(' ');
    if (!isdigit(log1[p1+1]) && !isdigit(log2[p2+1])) {
        return log1.substr(p1 + 1) < log2.substr(p2 + 1);
    }
    else {
        if (!isdigit(log1[p1+1])) 
            return true;
        return false;
    }
}

class Solution {
public:
    vector reorderLogFiles(vector& logs) {
        stable_sort(logs.begin(), logs.end(), logCompare);
        return logs;
    }
};

Review:

(Not completed, will continue next week.)
Article: The Log: What every software engineer should know about real-time data's unifying abstraction
Notes:

A log is really just a kind of table or file where the records are sorted by time.
Logs have a specific purpose: they record what happened and when.

Logs in databases

Over-time the usage of the log grew from an implementation detail of ACID to a method for replicating data between databases.

Logs in distributed systems

The purpose of the log here is to squeeze all the non-determinism out of the input stream to ensure that each replica processing this input stays in sync.

Database people generally differentiate between physical and logical logging. Physical logging means logging the contents of each row that is changed. Logical logging means logging not the changed rows but the SQL commands that lead to the row changes (the insert, update, and delete statements).
The distributed systems literature commonly distinguishes two broad approaches to processing and replication.


ARTS Week 1_第1张图片
Changelog 101: Tables and Events are Dual

Tables support data at rest and logs capture change.
Log is a sort of backup of every previous state of the table.
A version control system usually models the sequence of patches, which is in effect a log.

Tip:

When you want to test a new feature of your project. You want to select 10% of the users to test if the feature is welcome. You can use the hash of userId to decide if the feature is open to the user.

e.g. The range of hashCode is -2147483648 to -2147483647.
If you want to select 10% users, you can do it like below:

bool openNewFeature(string userId)
{
    if (abs(hashCode(userId)) <  10 * 21474836) 
        return true;
    else 
        return false;
}

A way to control the Roll Up when you want to

Share:

后端架构师技术图谱
To my knowledge, I can't identify weather it is a good guide. But at least we can know what kind of knowledge we should learn it we want to be an architect. And it also provides many resources.

Follow Up:

  1. Complete the article
  2. Paxos Algorithm

你可能感兴趣的:(ARTS Week 1)