Skip to content

Instantly share code, notes, and snippets.

@pccowboy
Created January 25, 2017 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pccowboy/7662e3ebae0f2257acd9405c1f480272 to your computer and use it in GitHub Desktop.
Save pccowboy/7662e3ebae0f2257acd9405c1f480272 to your computer and use it in GitHub Desktop.
Trying to prevent puts that overwrite by using the If-None-Match header, but not working as I expected...
[root@9ba10395 (ops) ~]$ mls -li /zettit_ops/stor/docs_test/117/24
-rwxr-xr-x 1 zettit_ops 4 Jan 25 11:08 test
-rwxr-xr-x 1 zettit_ops 6 Jan 25 11:37 test2
-rwxr-xr-x 1 zettit_ops 8 Jan 25 11:42 test3
[root@9ba10395 (ops) ~]$
[root@9ba10395 (ops) ~]$
[root@9ba10395 (ops) ~]$ # This one should fail, a version of the resource is present
[root@9ba10395 (ops) ~]$ mput -i --header='If-None-Match: *' /zettit_ops/stor/docs_test/117/24/test3
mput: Cannot write because HTTP precondition not met.
[root@9ba10395 (ops) ~]$
[root@9ba10395 (ops) ~]$
[root@9ba10395 (ops) ~]$ # This one I expected to complete successfully, but it fails
[root@9ba10395 (ops) ~]$ mput -i --header='If-None-Match: *' /zettit_ops/stor/docs_test/117/24/test4
mput: Cannot write because HTTP precondition not met.
@pccowboy
Copy link
Author

pccowboy commented Jan 25, 2017

For comparison, here is the request and response object from a perl LWP sessions, where I am trying to PUT a new document:

PUT https://manta.usw1.pccowboy.com/zettit_ops/stor/docs_test/117/24/4b192dd2-3c
1c-595d-846f-de209870a9a3
Date: Wed, 25 Jan 2017 17:55:35 GMT
Authorization: Signature keyId="/zettit_ops/runner/keys/<redacted>",algorithm="rsa-sha256",headers="Date",signature="<redacted>"
If-None-Match: *
User-Agent: libwww-perl/6.15
Content-Type: application/json
Role: manta_runner

{"rss":{"headline_id":null,"former_id":"11a991b496bce6d4d365fe805ce13626d8fc049f
","timestamp":1485366933.24419,"description":"PROVIDENCE, R.I.--(BUSINESS WIRE)-
-Textron Inc. (NYSE: TXT) today reported fourth quarter 2016 income from continu
ing operations of $0.78 per share compared to $0.81 per share in the fourth quar
ter of 2015. During this year\xC3\xA2\xC2\x80\xC2\x99s fourth quarter, the compa
ny recorded an $8 million pre-tax restructuring charge ($0.02 per share, after-t
ax). Excluding this item, adjusted income from con...
(+ 685 more bytes not shown)
HTTP/1.1 412 Precondition Failed
Connection: keep-alive
Date: Wed, 25 Jan 2017 17:55:35 GMT
Server: Manta
Content-Length: 75
Content-MD5: qMAMT1aHkWKjDs+hD3fb1g==
Content-Type: application/json
Client-Date: Wed, 25 Jan 2017 17:55:35 GMT
Client-Peer: 10.67.42.144:443
Client-Response-Num: 6
Client-SSL-Cert-Issuer: /C=US/ST=CA/O=Joyent/OU=manta/CN=manta.usw1.pccowboy.com
Client-SSL-Cert-Subject: /C=US/ST=CA/O=Joyent/OU=manta/CN=manta.usw1.pccowboy.com
Client-SSL-Cipher: AES128-GCM-SHA256
Client-SSL-Socket-Class: IO::Socket::SSL
Client-SSL-Warning: Peer certificate not verified
X-Request-Id: 78d4cae0-e327-11e6-a11f-418669b0a55e
X-Response-Time: 9
X-Server-Name: 7333c335-b620-4f7f-acc7-188ad3534190

{"code":"PreconditionFailed","message":"if-none-match '*' matched etag ''"}
117/0/25 17:55:35  Attempted to write duplicate for [4b192dd2-3c1c-595d-846f-de2
09870a9a3]

The directory contains:

[root@9ba10395 (ops) ~]$ mls -li /zettit_ops/stor/docs_test/117/24
-rwxr-xr-x 1 zettit_ops             4 Jan 25 11:08 test
-rwxr-xr-x 1 zettit_ops             6 Jan 25 11:37 test2
-rwxr-xr-x 1 zettit_ops             8 Jan 25 11:42 test3
[root@9ba10395 (ops) ~]$

@pccowboy
Copy link
Author

pccowboy commented Jan 27, 2017

And here is the same result in a session on my instance in joyent's us-east-1 datacenter:

[root@8e1e27f5-cddb-4f31-a898-a69630493fba ~]# mls -l
drwxr-xr-x 1 zettitops             0 Mar 08  2016 .joyent
[root@8e1e27f5-cddb-4f31-a898-a69630493fba ~]# mls -l  /$MANTA_USER/stor/
drwxr-xr-x 1 zettitops             0 Mar 08  2016 .joyent
[root@8e1e27f5-cddb-4f31-a898-a69630493fba ~]#  mmkdir ~~/stor/documents
[root@8e1e27f5-cddb-4f31-a898-a69630493fba ~]#
[root@8e1e27f5-cddb-4f31-a898-a69630493fba ~]# mls -l  ~~/stor/documents
[root@8e1e27f5-cddb-4f31-a898-a69630493fba ~]#  mput -v -i --header='If-None-Match: *'  ~~/stor/documents/test1
{"name":"mput","hostname":"8e1e27f5-cddb-4f31-a898-a69630493fba","pid":41781,"component":"MantaClient","path":"/zettitops/stor/documents/test1","req_id":"2572c2b5-851a-45aa-a431-2544f06b731f","level":20,"headers":{"accept":"application/json, */*","x-request-id":"2572c2b5-851a-45aa-a431-2544f06b731f"},"id":"2572c2b5-851a-45aa-a431-2544f06b731f","query":{},"msg":"info: entered","time":"2017-01-27T13:11:04.635Z","src":{"file":"/usr/lib/node_modules/manta/lib/client.js","line":1098,"func":"info"},"v":0}
{"name":"mput","hostname":"8e1e27f5-cddb-4f31-a898-a69630493fba","pid":41781,"component":"MantaClient","level":10,"client_req":{"method":"HEAD","url":"/zettitops/stor/documents/test1","address":"us-east.manta.joyent.com","port":null,"headers":{"accept":"application/json, */*","x-request-id":"2572c2b5-851a-45aa-a431-2544f06b731f","date":"Fri, 27 Jan 2017 13:11:04 GMT","authorization":"Signature keyId=\"/zettitops/keys/3b:bc:f3:fd:fa:0f:74:63:84:c0:8c:e6:42:74:3f:3e\",algorithm=\"rsa-sha256\",headers=\"date\",signature=\"dm6uXyILQwgBjTGlvOE0RtIDPh4GR4/3xKTa4gjnyN4WMKBTixu4O2y2bxOa5gYj2Bl38EFoJ64JWvM28aJhji1MB80Vd3DNCIlciBumEUuo6WibVG8/7FiJu5qOstFhnsMMezbKQiqftpLo7/Jd5llBDuEZlacj3vJpkNYZLJ8oZjslHOMBK5jxDj9gB7OoLoe74uasbqtIymgrHuBFiRm07feAyEGEV+H2GP0FxDqXr0DAnKbRuYigYmTB354qRY2UnpNA1hA+v03sFqtY3ZUXdFUm5N2ehDK0oWyaznIl+n6cyXFzs5Z1c87AXlU7VCyMb3KyG642Bz3C3O4/Sw==\"","if-none-match":"*","user-agent":"restify/1.3.0 (x64-linux; v8/5.1.281.83; OpenSSL/1.0.2h) node/6.6.0","accept-version":"~1.0"}},"msg":"request sent","time":"2017-01-27T13:11:05.045Z","src":{"file":"/usr/lib/node_modules/manta/node_modules/restify-clients/lib/HttpClient.js","line":314,"func":"rawRequest"},"v":0}
{"name":"mput","hostname":"8e1e27f5-cddb-4f31-a898-a69630493fba","pid":41781,"component":"MantaClient","level":10,"client_res":{"statusCode":404,"headers":{"content-type":"application/json","content-length":"85","content-md5":"yVzJZ4p0QX65yWIXhfV0lg==","date":"Fri, 27 Jan 2017 13:11:05 GMT","server":"Manta","x-request-id":"2572c2b5-851a-45aa-a431-2544f06b731f","x-response-time":"14","x-server-name":"c84b3cab-1c20-4566-a880-0e202b6b63dd","connection":"keep-alive","x-request-received":1485522664932,"x-request-processing-time":303}},"msg":"Response received","time":"2017-01-27T13:11:05.236Z","src":{"file":"/usr/lib/node_modules/manta/node_modules/restify-clients/lib/HttpClient.js","line":210,"func":"onResponse"},"v":0}
{"name":"mput","hostname":"8e1e27f5-cddb-4f31-a898-a69630493fba","pid":41781,"component":"MantaClient","path":"/zettitops/stor/documents/test1","req_id":"2f7e1891-8177-4fbb-b186-c715334c7d4c","level":20,"headers":{"if-none-match":"*","accept":"application/json","content-type":"application/octet-stream","expect":"100-continue","x-request-id":"2f7e1891-8177-4fbb-b186-c715334c7d4c","x-durability-level":2,"transfer-encoding":"chunked"},"id":"2f7e1891-8177-4fbb-b186-c715334c7d4c","query":{},"_original_path":"/zettitops/stor/documents/test1","msg":"put: entered","time":"2017-01-27T13:11:05.270Z","src":{"file":"/usr/lib/node_modules/manta/lib/client.js","line":1842,"func":"put"},"v":0}
{"name":"mput","hostname":"8e1e27f5-cddb-4f31-a898-a69630493fba","pid":41781,"component":"MantaClient","level":10,"client_req":{"method":"PUT","url":"/zettitops/stor/documents/test1","address":"us-east.manta.joyent.com","port":null,"headers":{"if-none-match":"*","accept":"application/json","content-type":"application/octet-stream","expect":"100-continue","x-request-id":"2f7e1891-8177-4fbb-b186-c715334c7d4c","x-durability-level":2,"transfer-encoding":"chunked","date":"Fri, 27 Jan 2017 13:11:05 GMT","authorization":"Signature keyId=\"/zettitops/keys/3b:bc:f3:fd:fa:0f:74:63:84:c0:8c:e6:42:74:3f:3e\",algorithm=\"rsa-sha256\",headers=\"date\",signature=\"liWrr85jTeX0ix3n6m3clk0LQpMhsPM1ButjwMXwvYkiB1NVJQxaacOThpSlIdYkUfsmVceJ/7SywKITH9CaLW3bTaqhAKIhDj/6GutjFam44pGyoDK7VBuo7jNWknS5G7aQ0bUuLBXAcDc0Gg9WZlB1QIBrxF1gftUWh26DxkVRKNUy37yul1ipiqcJKeMHy3EJ4pbU9+hjGGVJ6lusVRtPQ+Z+Pji6K6jmvrw17gtUsnznWY0jmo+82km5lH1o8c5T9UBDZG0IX7hqqAU57CYf1QLJOIKtGEQmCd3QkI3retgSLy80onIaoKZ6Nd1TNvJ3bBMIyW9c5QEPprhVNA==\"","user-agent":"restify/1.3.0 (x64-linux; v8/5.1.281.83; OpenSSL/1.0.2h) node/6.6.0","accept-version":"~1.0"}},"msg":"request sent","time":"2017-01-27T13:11:05.361Z","src":{"file":"/usr/lib/node_modules/manta/node_modules/restify-clients/lib/HttpClient.js","line":314,"func":"rawRequest"},"v":0}
{"name":"mput","hostname":"8e1e27f5-cddb-4f31-a898-a69630493fba","pid":41781,"component":"MantaClient","level":10,"client_res":{"statusCode":412,"headers":{"content-type":"application/json","content-length":"75","content-md5":"qMAMT1aHkWKjDs+hD3fb1g==","date":"Fri, 27 Jan 2017 13:11:05 GMT","server":"Manta","x-request-id":"2f7e1891-8177-4fbb-b186-c715334c7d4c","x-response-time":"16","x-server-name":"511ea59e-2a4a-486b-9258-ef59016d064d","connection":"close","x-request-received":1485522665323,"x-request-processing-time":83}},"msg":"Response received","time":"2017-01-27T13:11:05.407Z","src":{"file":"/usr/lib/node_modules/manta/node_modules/restify-clients/lib/HttpClient.js","line":210,"func":"onResponse"},"v":0}
{"name":"mput","hostname":"8e1e27f5-cddb-4f31-a898-a69630493fba","pid":41781,"component":"MantaClient","path":"/zettitops/stor/documents/test1","req_id":"2f7e1891-8177-4fbb-b186-c715334c7d4c","level":20,"err":{"message":"if-none-match '*' matched etag ''","name":"PreconditionFailedError","stack":"PreconditionFailedError: if-none-match '*' matched etag ''\n    at ClientRequest.onResponse (/usr/lib/node_modules/manta/node_modules/restify-clients/lib/HttpClient.js:217:26)\n    at ClientRequest.g (events.js:291:16)\n    at emitOne (events.js:96:13)\n    at ClientRequest.emit (events.js:188:7)\n    at HTTPParser.parserOnIncomingClient (_http_client.js:472:21)\n    at HTTPParser.parserOnHeadersComplete (_http_common.js:99:23)\n    at TLSSocket.socketOnData (_http_client.js:361:20)\n    at emitOne (events.js:96:13)\n    at TLSSocket.emit (events.js:188:7)\n    at readableAddChunk (_stream_readable.js:176:18)","code":"PreconditionFailed"},"msg":"put: error","time":"2017-01-27T13:11:05.421Z","src":{"file":"/usr/lib/node_modules/manta/lib/client.js","line":330,"func":"onReadDone"},"v":0}
mput: Cannot write because HTTP precondition not met.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment