MapReduce上的数据丢失?

MapReduce上的数据丢失?,mapreduce,Mapreduce,我的代码执行10000行 映射器伪代码: int rows=0; map() {rows++} cleanup(Context c) {print(rows)} int rows=0; reduce() {rows++} cleanup(Context c) {print(rows)} public static enum COUNTER {ROW}; map() {row=context.getCounter(RWDriver.COUNTER.ROW

我的代码执行10000行

映射器伪代码:

int rows=0;
map()
   {rows++}  
cleanup(Context c)
   {print(rows)}
int rows=0;
reduce()
   {rows++}  
cleanup(Context c)
   {print(rows)}
public static enum COUNTER {ROW};
map()
   {row=context.getCounter(RWDriver.COUNTER.ROW).increment(1);
    context.write(row,new Text(...))
   }     
cleanup(Context c)
   {print(c.getCounter(RWDriver.COUNTER.ROW).getValue());}
此代码打印:

2669
3354
3353
621
(sum=9997)
2670
3355
3354
622
(sum=10001 correct)
为什么总数是9997

减速机伪代码:

int rows=0;
map()
   {rows++}  
cleanup(Context c)
   {print(rows)}
int rows=0;
reduce()
   {rows++}  
cleanup(Context c)
   {print(rows)}
public static enum COUNTER {ROW};
map()
   {row=context.getCounter(RWDriver.COUNTER.ROW).increment(1);
    context.write(row,new Text(...))
   }     
cleanup(Context c)
   {print(c.getCounter(RWDriver.COUNTER.ROW).getValue());}
减速器打印: 3354

其他数据都在哪里

编辑1

我发现了主要问题

我的错误是发送的键是行的编号。当映射程序调用
cleanup()
函数时,它会重置行计数器(保存在应用程序的驱动程序中)。因此,密钥不是唯一的。我可以通过从map函数的参数发送密钥来解决这个问题吗?我认为
cleanup()
不会重置此参数

如果在应用程序的驱动程序中使用全局变量,是否存在同步问题

编辑2

我的代码执行10000行(和1个标题行)

驱动程序伪代码:

int rows=0;
map()
   {rows++}  
cleanup(Context c)
   {print(rows)}
int rows=0;
reduce()
   {rows++}  
cleanup(Context c)
   {print(rows)}
public static enum COUNTER {ROW};
map()
   {row=context.getCounter(RWDriver.COUNTER.ROW).increment(1);
    context.write(row,new Text(...))
   }     
cleanup(Context c)
   {print(c.getCounter(RWDriver.COUNTER.ROW).getValue());}
映射器伪代码:

int rows=0;
map()
   {rows++}  
cleanup(Context c)
   {print(rows)}
int rows=0;
reduce()
   {rows++}  
cleanup(Context c)
   {print(rows)}
public static enum COUNTER {ROW};
map()
   {row=context.getCounter(RWDriver.COUNTER.ROW).increment(1);
    context.write(row,new Text(...))
   }     
cleanup(Context c)
   {print(c.getCounter(RWDriver.COUNTER.ROW).getValue());}
此代码打印:

2669
3354
3353
621
(sum=9997)
2670
3355
3354
622
(sum=10001 correct)

26703355之后,缓冲区已满,MapReduce会自动将计数器行重置为0。我需要实际的行数,但这种方法不起作用。

数据的解释可能是错误的

您应该使用Map Reduce框架计数器或用户定义的计数器:


映射减少框架计数器
用户定义计数器 同样地,在减速器中也是如此

获取计数器的值
您可以共享Map Reduce计数器值吗?