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<string> reorderLogFiles(vector<string>& 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.


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:

后端架構(gòu)師技術(shù)圖譜
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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末李茫,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌敲霍,老刑警劉巖坚俗,帶你破解...
    沈念sama閱讀 218,451評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異碉熄,居然都是意外死亡杂数,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,172評論 3 394
  • 文/潘曉璐 我一進店門锉试,熙熙樓的掌柜王于貴愁眉苦臉地迎上來猫十,“玉大人,你說我怎么就攤上這事呆盖⊥显疲” “怎么了?”我有些...
    開封第一講書人閱讀 164,782評論 0 354
  • 文/不壞的土叔 我叫張陵应又,是天一觀的道長宙项。 經(jīng)常有香客問我,道長株扛,這世上最難降的妖魔是什么尤筐? 我笑而不...
    開封第一講書人閱讀 58,709評論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮洞就,結(jié)果婚禮上盆繁,老公的妹妹穿的比我還像新娘。我一直安慰自己旬蟋,他們只是感情好油昂,可當我...
    茶點故事閱讀 67,733評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著倾贰,像睡著了一般冕碟。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上匆浙,一...
    開封第一講書人閱讀 51,578評論 1 305
  • 那天安寺,我揣著相機與錄音,去河邊找鬼首尼。 笑死挑庶,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的饰恕。 我是一名探鬼主播挠羔,決...
    沈念sama閱讀 40,320評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼埋嵌!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起俱恶,我...
    開封第一講書人閱讀 39,241評論 0 276
  • 序言:老撾萬榮一對情侶失蹤雹嗦,失蹤者是張志新(化名)和其女友劉穎范舀,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體了罪,經(jīng)...
    沈念sama閱讀 45,686評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡锭环,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,878評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了泊藕。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片辅辩。...
    茶點故事閱讀 39,992評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖娃圆,靈堂內(nèi)的尸體忽然破棺而出玫锋,到底是詐尸還是另有隱情,我是刑警寧澤讼呢,帶...
    沈念sama閱讀 35,715評論 5 346
  • 正文 年R本政府宣布撩鹿,位于F島的核電站,受9級特大地震影響悦屏,放射性物質(zhì)發(fā)生泄漏节沦。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,336評論 3 330
  • 文/蒙蒙 一础爬、第九天 我趴在偏房一處隱蔽的房頂上張望甫贯。 院中可真熱鬧,春花似錦看蚜、人聲如沸获搏。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,912評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽常熙。三九已至,卻和暖如春碱茁,著一層夾襖步出監(jiān)牢的瞬間裸卫,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,040評論 1 270
  • 我被黑心中介騙來泰國打工纽竣, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留墓贿,地道東北人。 一個月前我還...
    沈念sama閱讀 48,173評論 3 370
  • 正文 我出身青樓蜓氨,卻偏偏與公主長得像聋袋,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子穴吹,可洞房花燭夜當晚...
    茶點故事閱讀 44,947評論 2 355

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,332評論 0 10
  • 苔下石滴血幽勒,堤上枯柳凄。斷弦碎玉染港令,絕書枯墨散啥容。棋亂局殘醒锈颗,茶落素衣沾。墳前落花冷咪惠,亡魂泣聲寒击吱。
    麋鹿林1999閱讀 221評論 4 4
  • 今天小編為大家講到的是兩位大佬級人物,我想作為像小編這個年紀的人遥昧,都是看他們的電影長大的覆醇。對于他們的發(fā)展我相信很多...
    袁俊俊閱讀 267評論 0 0
  • 開篇:一切不以“行為”改變的學習都是耍流氓! 如果每次來上課炭臭,只是來聽聽永脓,沒有改變自身行為的行動項,那我們永遠都不...
    大萌在路上閱讀 317評論 1 0