title: Hadoop put command throws - could only be replicated to 0 nodes, instead of 1
body: <p>I am new to Hadoop, I am trying to do pseudo distributed mode setup on my ubuntu machine and facing an issue with <code>hadoop put</code> command. My configuration details are available in this post --> <a href="https://stackoverflow.com/questions/27143409/what-the-command-hadoop-namenode-format-will-do">What the command &quot;hadoop namenode -format&quot; will do</a></p>
  
  <p>Now I am trying to add some files to HDFS using below commands:</p>
  
  <pre><code>hadoop fs –mkdir /user/myuser
  
  hadoop fs -lsr /
  
  $ ./hadoop fs -lsr /
  drwxr-xr-x   - myuser supergroup          0 2014-11-26 16:04 /tmp
  drwxr-xr-x   - myuser supergroup          0 2014-11-26 16:04 /tmp/hadoop-myuser
  drwxr-xr-x   - myuser supergroup          0 2014-11-26 16:04 /tmp/hadoop-myuser/dfs
  -rw-r--r--   1 myuser supergroup          0 2014-11-26 16:04 /tmp/hadoop-myuser/dfs/name
  drwxr-xr-x   - myuser supergroup          0 2014-11-26 16:04 /tmp/hadoop-myuser/mapred
  drwx------   - myuser supergroup          0 2014-11-26 16:12 /tmp/hadoop-myuser/mapred/system
  drwxr-xr-x   - myuser supergroup          0 2014-11-26 16:04 /user
  drwxr-xr-x   - myuser supergroup          0 2014-11-26 16:06 /user/myuser
  </code></pre>
  
  <p>Now I am running the <code>put</code> command but getting exception like this:</p>
  
  <pre><code>$ ./hadoop fs -put example.txt .
  14/11/26 16:06:19 WARN hdfs.DFSClient: DataStreamer Exception: org.apache.hadoop.ipc.RemoteException: java.io.IOException: File /user/myuser/example.txt could only be replicated to 0 nodes, instead of 1
      at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock(FSNamesystem.java:1920)
      at org.apache.hadoop.hdfs.server.namenode.NameNode.addBlock(NameNode.java:783)
      at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:587)
      at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1432)
      at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1428)
      at java.security.AccessController.doPrivileged(Native Method)
      at javax.security.auth.Subject.doAs(Subject.java:396)
      at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1190)
      at org.apache.hadoop.ipc.Server$Handler.run(Server.java:1426)
  
      at org.apache.hadoop.ipc.Client.call(Client.java:1113)
      at org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:229)
      at com.sun.proxy.$Proxy1.addBlock(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:85)
      at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:62)
      at com.sun.proxy.$Proxy1.addBlock(Unknown Source)
      at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.locateFollowingBlock(DFSClient.java:3720)
      at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.nextBlockOutputStream(DFSClient.java:3580)
      at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.access$2600(DFSClient.java:2783)
      at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream$DataStreamer.run(DFSClient.java:3023)
  
  14/11/26 16:06:19 WARN hdfs.DFSClient: Error Recovery for null bad datanode[0] nodes == null
  14/11/26 16:06:19 WARN hdfs.DFSClient: Could not get block locations. Source file "/user/myuser/example.txt" - Aborting...
  put: java.io.IOException: File /user/myuser/example.txt could only be replicated to 0 nodes, instead of 1
  14/11/26 16:06:19 ERROR hdfs.DFSClient: Failed to close file /user/myuser/example.txt
  org.apache.hadoop.ipc.RemoteException: java.io.IOException: File /user/myuser/example.txt could only be replicated to 0 nodes, instead of 1
      at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock(FSNamesystem.java:1920)
      at org.apache.hadoop.hdfs.server.namenode.NameNode.addBlock(NameNode.java:783)
      at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:587)
      at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1432)
      at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1428)
      at java.security.AccessController.doPrivileged(Native Method)
      at javax.security.auth.Subject.doAs(Subject.java:396)
      at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1190)
      at org.apache.hadoop.ipc.Server$Handler.run(Server.java:1426)
  
      at org.apache.hadoop.ipc.Client.call(Client.java:1113)
      at org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:229)
      at com.sun.proxy.$Proxy1.addBlock(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:85)
      at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:62)
      at com.sun.proxy.$Proxy1.addBlock(Unknown Source)
      at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.locateFollowingBlock(DFSClient.java:3720)
      at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.nextBlockOutputStream(DFSClient.java:3580)
      at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.access$2600(DFSClient.java:2783)
      at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream$DataStreamer.run(DFSClient.java:3023)
  </code></pre>
  
  <p>Can someone please help me how can I fix this issue?</p>
  
  <p><strong>Solution to the issue:</strong></p>
  
  <p>Based on answers provided I am able to solve the issue by following below steps:</p>
  
  <p>1) Stop all services:</p>
  
  <pre><code>./stop-all.sh
  </code></pre>
  
  <p>2) Delete the data directory:</p>
  
  <pre><code>rm -rf /tmp/hadoop-myuser/dfs/data/
  </code></pre>
  
  <p>3) Start the services:</p>
  
  <pre><code>./start-all.sh
  </code></pre>
  
  <p>4) Then put the file into HDFS:</p>
  
  <pre><code>./hadoop fs -put example.txt .
  </code></pre>