You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

302 lines
7.8 KiB

11 years ago
  1. API
  2. ===================================
  3. Master server
  4. ###################################
  5. You can append to any HTTP API with &pretty=y to see a formatted json output.
  6. Assign a file key
  7. ***********************************
  8. .. code-block:: bash
  9. # Basic Usage:
  10. curl http://localhost:9333/dir/assign
  11. {"count":1,"fid":"3,01637037d6","url":"127.0.0.1:8080",
  12. "publicUrl":"localhost:8080"}
  13. # To assign with a specific replication type:
  14. curl "http://localhost:9333/dir/assign?replication=001"
  15. # To specify how many file ids to reserve
  16. curl "http://localhost:9333/dir/assign?count=5"
  17. # To assign a specific data center
  18. curl "http://localhost:9333/dir/assign?dataCenter=dc1"
  19. Lookup volume
  20. ***********************************
  21. We would need to find out whether the volumes have moved.
  22. .. code-block:: bash
  23. curl "http://localhost:9333/dir/lookup?volumeId=3&pretty=y"
  24. {
  25. "locations": [
  26. {
  27. "publicUrl": "localhost:8080",
  28. "url": "localhost:8080"
  29. }
  30. ]
  31. }
  32. # Other usages:
  33. # You can actually use the file id to lookup
  34. curl "http://localhost:9333/dir/lookup?volumeId=3,01637037d6"
  35. # If you know the collection, specify it since it will be a little faster
  36. curl "http://localhost:9333/dir/lookup?volumeId=3&collection=turbo"
  37. Force garbage collection
  38. ***********************************
  39. If your system has many deletions, the deleted file's disk space will not be synchronously re-claimed. There is a background job to check volume disk usage. If empty space is more than the threshold, default to 0.3, the vacuum job will make the volume readonly, create a new volume with only existing files, and switch on the new volume. If you are impatient or doing some testing, vacuum the unused spaces this way.
  40. .. code-block:: bash
  41. curl "http://localhost:9333/vol/vacuum"
  42. curl "http://localhost:9333/vol/vacuum?garbageThreshold=0.4"
  43. The garbageThreshold=0.4 is optional, and will not change the default threshold. You can start volume master with a different default garbageThreshold.
  44. Pre-Allocate Volumes
  45. ***********************************
  46. One volume servers one write a time. If you need to increase concurrency, you can pre-allocate lots of volumes.
  47. .. code-block:: bash
  48. curl "http://localhost:9333/vol/grow?replication=000&count=4"
  49. {"count":4}
  50. # specify a collection
  51. curl "http://localhost:9333/vol/grow?collection=turbo&count=4"
  52. # specify data center
  53. curl "http://localhost:9333/vol/grow?dataCenter=dc1&count=4"
  54. This generates 4 empty volumes.
  55. Upload File Directly
  56. ***********************************
  57. .. code-block:: bash
  58. curl -F file=@/home/chris/myphoto.jpg http://localhost:9333/submit
  59. {"fid":"3,01fbe0dc6f1f38","fileName":"myphoto.jpg",
  60. "fileUrl":"localhost:8080/3,01fbe0dc6f1f38","size":68231}
  61. This API is a little convenient. The master server would contact itself via HTTP to get an file id and store it to the right volume server. It is a convenient API and does not support different parameters when assigning file id.
  62. Check System Status
  63. ***********************************
  64. .. code-block:: bash
  65. curl "http://10.0.2.15:9333/cluster/status?pretty=y"
  66. {
  67. "IsLeader": true,
  68. "Leader": "10.0.2.15:9333",
  69. "Peers": [
  70. "10.0.2.15:9334",
  71. "10.0.2.15:9335"
  72. ]
  73. }
  74. curl "http://localhost:9333/dir/status?pretty=y"
  75. {
  76. "Topology": {
  77. "DataCenters": [
  78. {
  79. "Free": 3,
  80. "Id": "dc1",
  81. "Max": 7,
  82. "Racks": [
  83. {
  84. "DataNodes": [
  85. {
  86. "Free": 3,
  87. "Max": 7,
  88. "PublicUrl": "localhost:8080",
  89. "Url": "localhost:8080",
  90. "Volumes": 4
  91. }
  92. ],
  93. "Free": 3,
  94. "Id": "DefaultRack",
  95. "Max": 7
  96. }
  97. ]
  98. },
  99. {
  100. "Free": 21,
  101. "Id": "dc3",
  102. "Max": 21,
  103. "Racks": [
  104. {
  105. "DataNodes": [
  106. {
  107. "Free": 7,
  108. "Max": 7,
  109. "PublicUrl": "localhost:8081",
  110. "Url": "localhost:8081",
  111. "Volumes": 0
  112. }
  113. ],
  114. "Free": 7,
  115. "Id": "rack1",
  116. "Max": 7
  117. },
  118. {
  119. "DataNodes": [
  120. {
  121. "Free": 7,
  122. "Max": 7,
  123. "PublicUrl": "localhost:8082",
  124. "Url": "localhost:8082",
  125. "Volumes": 0
  126. },
  127. {
  128. "Free": 7,
  129. "Max": 7,
  130. "PublicUrl": "localhost:8083",
  131. "Url": "localhost:8083",
  132. "Volumes": 0
  133. }
  134. ],
  135. "Free": 14,
  136. "Id": "DefaultRack",
  137. "Max": 14
  138. }
  139. ]
  140. }
  141. ],
  142. "Free": 24,
  143. "Max": 28,
  144. "layouts": [
  145. {
  146. "collection": "",
  147. "replication": "000",
  148. "writables": [
  149. 1,
  150. 2,
  151. 3,
  152. 4
  153. ]
  154. }
  155. ]
  156. },
  157. "Version": "0.47"
  158. }
  159. Volume Server
  160. ###################################
  161. Upload File
  162. ***********************************
  163. .. code-block:: bash
  164. curl -F file=@/home/chris/myphoto.jpg http://127.0.0.1:8080/3,01637037d6
  165. {"size": 43234}
  166. The size returned is the size stored on WeedFS, sometimes the file is automatically gzipped based on the mime type.
  167. Upload File Directly
  168. ***********************************
  169. .. code-block:: bash
  170. curl -F file=@/home/chris/myphoto.jpg http://localhost:8080/submit
  171. {"fid":"3,01fbe0dc6f1f38","fileName":"myphoto.jpg","fileUrl":"localhost:8080/3,01fbe0dc6f1f38","size":68231}
  172. This API is a little convenient. The volume server would contact the master to get an file id and store it to the right volume server(not necessarily itself).
  173. Delete File
  174. ***********************************
  175. .. code-block:: bash
  176. curl -X DELETE http://127.0.0.1:8080/3,01637037d6
  177. Create а specific volume on a specific volume server
  178. *****************************************************
  179. .. code-block:: bash
  180. curl "http://localhost:8080/admin/assign_volume?replication=000&volume=3"
  181. This generates volume 3 on this volume server.
  182. If you use other replicationType, e.g. 001, you would need to do the same on other volume servers to create the mirroring volumes.
  183. Check Volume Server Status
  184. ***********************************
  185. .. code-block:: bash
  186. curl "http://localhost:8080/status?pretty=y"
  187. {
  188. "Version": "0.34",
  189. "Volumes": [
  190. {
  191. "Id": 1,
  192. "Size": 1319688,
  193. "RepType": "000",
  194. "Version": 2,
  195. "FileCount": 276,
  196. "DeleteCount": 0,
  197. "DeletedByteCount": 0,
  198. "ReadOnly": false
  199. },
  200. {
  201. "Id": 2,
  202. "Size": 1040962,
  203. "RepType": "000",
  204. "Version": 2,
  205. "FileCount": 291,
  206. "DeleteCount": 0,
  207. "DeletedByteCount": 0,
  208. "ReadOnly": false
  209. },
  210. {
  211. "Id": 3,
  212. "Size": 1486334,
  213. "RepType": "000",
  214. "Version": 2,
  215. "FileCount": 301,
  216. "DeleteCount": 2,
  217. "DeletedByteCount": 0,
  218. "ReadOnly": false
  219. },
  220. {
  221. "Id": 4,
  222. "Size": 8953592,
  223. "RepType": "000",
  224. "Version": 2,
  225. "FileCount": 320,
  226. "DeleteCount": 2,
  227. "DeletedByteCount": 0,
  228. "ReadOnly": false
  229. },
  230. {
  231. "Id": 5,
  232. "Size": 70815851,
  233. "RepType": "000",
  234. "Version": 2,
  235. "FileCount": 309,
  236. "DeleteCount": 1,
  237. "DeletedByteCount": 0,
  238. "ReadOnly": false
  239. },
  240. {
  241. "Id": 6,
  242. "Size": 1483131,
  243. "RepType": "000",
  244. "Version": 2,
  245. "FileCount": 301,
  246. "DeleteCount": 1,
  247. "DeletedByteCount": 0,
  248. "ReadOnly": false
  249. },
  250. {
  251. "Id": 7,
  252. "Size": 46797832,
  253. "RepType": "000",
  254. "Version": 2,
  255. "FileCount": 292,
  256. "DeleteCount": 0,
  257. "DeletedByteCount": 0,
  258. "ReadOnly": false
  259. }
  260. ]
  261. }