你好,游客 登录 注册 搜索
背景:
阅读新闻

Hadoop分析之二元数据备份方案的机制

[日期:2012-07-24] 来源:blog.csdn.net/kntao  作者:kntao [字体:大 中 小]
1、NameNode启动加载元数据情景分析
  • NameNode函数里调用FSNamesystemm读取dfs.namenode.name.dir和dfs.namenode.edits.dir构建FSDirectory。
  • FSImage类recoverTransitionRead和saveNameSpace分别实现了元数据的检查、加载、内存合并和元数据的持久化存储。
  • saveNameSpace将元数据写入到磁盘,具体操作步骤:首先将current目录重命名为lastcheckpoint.tmp;然后在创建新的current目录,并保存文件;最后将lastcheckpoint.tmp重命名为privios.checkpoint.
  • checkPoint的过程:Secondary NameNode会通知nameNode产生一个edit log文件edits.new,之后所有的日志操作写入到edits.new文件中。接下来Secondary NameNode会从namenode下载fsimage和edits文件,进行合并产生新的fsimage.ckpt;然后Secondary会将fsimage.ckpt文件上传到namenode。最后namenode会重命名fsimage.ckpt为fsimage,edtis.new为edits;
2、元数据更新及日志写入情景分析
以mkdir为例:
logSync代码分析:
代码:
  1. public void logSync () throws IOException {  
  2. ArrayList<EditLogOutputStream > errorStreams = null ;  
  3. long syncStart = 0;  
  4.   
  5. // Fetch the transactionId of this thread.   
  6. long mytxid = myTransactionId .get (). txid;  
  7. EditLogOutputStream streams[] = null;  
  8. boolean sync = false;  
  9. try {  
  10. synchronized (this) {  
  11. assert editStreams. size() > 0 : "no editlog streams" ;  
  12. printStatistics (false);  
  13. // if somebody is already syncing, then wait   
  14. while (mytxid > synctxid && isSyncRunning) {  
  15. try {  
  16. wait (1000 );  
  17. } catch (InterruptedException ie ) {  
  18. }  
  19. }  
  20. //   
  21. // If this transaction was already flushed, then nothing to do   
  22. //   
  23. if (mytxid <= synctxid ) {  
  24. numTransactionsBatchedInSync ++;  
  25. if (metrics != null) // Metrics is non-null only when used inside name node   
  26. metrics .transactionsBatchedInSync .inc ();  
  27. return;  
  28. }  
  29. // now, this thread will do the sync   
  30. syncStart = txid ;  
  31. isSyncRunning = true;  
  32. sync = true;  
  33. // swap buffers   
  34. for( EditLogOutputStream eStream : editStreams ) {  
  35. eStream .setReadyToFlush ();  
  36. }  
  37. streams =  
  38. editStreams .toArray (new EditLogOutputStream[editStreams. size()]) ;  
  39. }  
  40. // do the sync   
  41. long start = FSNamesystem.now();  
  42. for (int idx = 0; idx < streams. length; idx++ ) {  
  43. EditLogOutputStream eStream = streams [idx ];  
  44. try {  
  45. eStream .flush ();  
  46. } catch (IOException ie ) {  
  47. FSNamesystem .LOG .error ("Unable to sync edit log." , ie );  
  48. //   
  49. // remember the streams that encountered an error.   
  50. //   
  51. if (errorStreams == null) {  
  52. errorStreams = new ArrayList <EditLogOutputStream >( 1) ;  
  53. }  
  54. errorStreams .add (eStream );  
  55. }  
  56. }  
  57. long elapsed = FSNamesystem.now() - start ;  
  58. processIOError (errorStreams , true);  
  59. if (metrics != null) // Metrics non-null only when used inside name node   
  60. metrics .syncs .inc (elapsed );  
  61. } finally {  
  62. synchronized (this) {  
  63. synctxid = syncStart ;  
  64. if (sync ) {  
  65. isSyncRunning = false;  
  66. }  
  67. this.notifyAll ();  
  68. }  
  69. }  
  70. }  
linux
相关资讯       Hadoop应用 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款