Skip to content

Commit b1a8654

Browse files
authored
GetObject by inode (#69)
1 parent 7e7d008 commit b1a8654

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

pkg/dataplane/http/context.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,14 @@ func (c *context) GetObjectSync(getObjectInput *v3io.GetObjectInput) (*v3io.Resp
519519
headers["Range"] = fmt.Sprintf("bytes=%v-%v", getObjectInput.Offset, getObjectInput.Offset+getObjectInput.NumBytes-1)
520520
}
521521

522+
if getObjectInput.CtimeSec > 0 {
523+
if headers == nil {
524+
headers = make(map[string]string)
525+
}
526+
headers["ctime-sec"] = fmt.Sprintf("%d", getObjectInput.CtimeSec)
527+
headers["ctime-nsec"] = fmt.Sprintf("%d", getObjectInput.CtimeNsec)
528+
}
529+
522530
return c.sendRequest(&getObjectInput.DataPlaneInput,
523531
http.MethodGet,
524532
getObjectInput.Path,

pkg/dataplane/test/sync_test.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func (suite *syncObjectTestSuite) TestObject() {
272272
suite.Require().NoError(err, "Failed to put")
273273

274274
//
275-
// Get the contents
275+
// Get the contents by path
276276
//
277277

278278
getObjectInput = &v3io.GetObjectInput{
@@ -291,6 +291,50 @@ func (suite *syncObjectTestSuite) TestObject() {
291291
// release the response
292292
response.Release()
293293

294+
//
295+
// Get object by inode
296+
//
297+
298+
// Get item attributes to find out what's the inode & ctime
299+
getItemInput := v3io.GetItemInput{
300+
Path: path,
301+
AttributeNames: []string{"**"},
302+
}
303+
304+
// when run against a context, will populate fields like container name
305+
suite.populateDataPlaneInput(&getItemInput.DataPlaneInput)
306+
307+
response, err = suite.container.GetItemSync(&getItemInput)
308+
suite.Require().NoError(err, "Failed to get item")
309+
310+
// parse item attributes and extract inode & ctime
311+
getItemOutput := response.Output.(*v3io.GetItemOutput)
312+
inode, err := getItemOutput.Item.GetFieldInt("__inode_number")
313+
suite.Require().NoError(err, "Failed to get inode")
314+
ctimeSec, err := getItemOutput.Item.GetFieldInt("__ctime_secs")
315+
suite.Require().NoError(err, "Failed to get ctime sec")
316+
ctimeNsec, err := getItemOutput.Item.GetFieldInt("__ctime_nsecs")
317+
suite.Require().NoError(err, "Failed to get ctime nsec")
318+
319+
// get object using inode and ctime
320+
getObjectInput = &v3io.GetObjectInput{
321+
Path: fmt.Sprintf("%d", inode),
322+
CtimeSec: ctimeSec,
323+
CtimeNsec: ctimeNsec,
324+
}
325+
326+
// when run against a context, will populate fields like container name
327+
suite.populateDataPlaneInput(&getObjectInput.DataPlaneInput)
328+
329+
response, err = suite.container.GetObjectSync(getObjectInput)
330+
suite.Require().NoError(err, "Failed to get")
331+
332+
// make sure buckets is not empty
333+
suite.Require().Equal(contents, string(response.Body()))
334+
335+
// release the response
336+
response.Release()
337+
294338
//
295339
// Delete the object
296340
//

pkg/dataplane/types.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,11 @@ type ContainerInfo struct {
181181

182182
type GetObjectInput struct {
183183
DataPlaneInput
184-
Path string
185-
Offset int
186-
NumBytes int
184+
Path string
185+
Offset int
186+
NumBytes int
187+
CtimeSec int
188+
CtimeNsec int
187189
}
188190

189191
type PutObjectInput struct {

0 commit comments

Comments
 (0)