Skip to content

Commit

Permalink
patch !1727 and #625
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-aizman committed Feb 25, 2020
1 parent 59928b8 commit f861fc8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 18 deletions.
3 changes: 3 additions & 0 deletions ais/tgtdaecp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,9 @@ func (t *targetrunner) commitCopyRenameLB(bckFrom, bckTo *cluster.Bck, msgInt *a
waiter.Add(1)
go xact.Run(waiter, msgInt.GlobRebID)
waiter.Wait()

time.Sleep(200 * time.Millisecond) // FIXME: !1727

case cmn.ActCopyBucket:
var xact *mirror.XactBckCopy
xact, err = xaction.Registry.RenewBckCopy(t, bckFrom, bckTo, cmn.ActCommit)
Expand Down
40 changes: 26 additions & 14 deletions cli/resources/object.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
## Object

The CLI allows users to interact with objects in the AIS cluster.
## Operations on objects

### GET

`ais get BUCKET_NAME/OBJECT_NAME OUT_FILE`

Gets the object from the bucket.
GET object from bucket.

| Flag | Type | Description | Default |
| --- | --- | --- | --- |
Expand Down Expand Up @@ -221,14 +219,27 @@ Deletes an object or list/range of objects from the bucket.
<a name="ft3">3</a> Options `--list,--range` and argument(s) `OBJECT_NAME` are mutually exclusive. List and range deletions expect only a bucket name; if one or more
`OBJECT_NAME`s are given, a separate `DELETE` request is sent for each object.
#### More Examples
#### Examples
| Command | Description |
| --- | --- |
| `ais rm object mybucket/myobj` | Deletes object `myobj` from bucket `mybucket` |
| `ais rm object aisbck/obj1 cloudbck/obj2` | Deletes two objects (`obj1`, `obj2`) from different buckets (`aisbck`, `cloudbck`) |
| `ais rm object mybucket/ --list "obj1,obj2,obj3"` | Deletes a list of objects (`obj1`, `obj2`, `obj3`) from bucket `mybucket` |
| `ais rm object mybucket/ --range "1:3" --prefix "test-" --regex "\\d\\d\\d"` | Deletes objects in range `001-003`, with prefix `test-`, matching `[0-9][0-9][0-9]` regex, from bucket `mybucket` |
1) Delete object `myobj` from bucket `mybucket`
```sh
$ ais rm object mybucket/myobj
```
2) Delete objects (`obj1`, `obj2`) from buckets (`aisbck`, `cloudbck`) respectively
```sh
$ ais rm object aisbck/obj1 cloudbck/obj2
```
3) Delete a list of objects (`obj1`, `obj2`, `obj3`) from bucket `mybucket`
```sh
$ ais rm object mybucket/ --list "obj1,obj2,obj3"
```
4) Delete all objects in range `001-003`, with prefix `test-`, matching `[0-9][0-9][0-9]` regex, from bucket `mybucket`
```sh
$ ais rm object mybucket/ --range "1:3" --prefix "test-" --regex "\\d\\d\\d"
```
### Evict
Expand Down Expand Up @@ -295,9 +306,10 @@ Renames object from an ais bucket.
#### Examples
| Command | Description |
| --- | --- |
| `ais rename object mybucket/obj obj1` | Renames object `obj` from bucket `mybucket` to `obj1` |
1) Rename object `obj1` as `obj2`
```sh
ais rename object mybucket/obj1 obj2
```
### Compose
Expand Down
25 changes: 22 additions & 3 deletions cmn/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,19 +811,38 @@ func RemoveFile(path string) error {
return nil
}

func IsDirEmpty(dir string) ([]string, bool, error) {
func IsDirEmpty(dir string, ignoreEmptySubdirs ...bool) ([]string, bool /* is empty */, error) {
var names []string
f, err := os.Open(dir)
if err != nil {
return nil, false, err
}
defer f.Close()

names, err = f.Readdirnames(2)
names, err = f.Readdirnames(3)
if err == io.EOF {
return nil, true, nil
}
return names, false, err
if err != nil {
return names, false, err
}
if len(names) == 0 {
return names, true, nil
}
if len(names) > 1 {
return names, false, nil
}
if len(ignoreEmptySubdirs) == 0 || !ignoreEmptySubdirs[0] {
return names, false, nil
}
// FIXME: #625
subdir := filepath.Join(dir, names[0])
if finfo, erc := os.Stat(subdir); erc == nil {
if finfo.IsDir() {
return IsDirEmpty(subdir)
}
}
return names, false, nil
}

// computes xxhash if requested
Expand Down
3 changes: 2 additions & 1 deletion fs/mountfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,8 @@ func (mi *MountpathInfo) createBckDirs(bck cmn.Bck) (num int, err error) {
for contentType := range CSM.RegisteredContentTypes {
dir := mi.MakePathCT(bck, contentType)
if err := Access(dir); err == nil {
if names, empty, errEmpty := cmn.IsDirEmpty(dir); errEmpty != nil {
// FIXME: ignore empty subdirs #625
if names, empty, errEmpty := cmn.IsDirEmpty(dir, true /*ignore empty subdirs*/); errEmpty != nil {
return num, errEmpty
} else if !empty {
return num, fmt.Errorf("bucket %s: directory %s already exists and is not empty (%v...)",
Expand Down

0 comments on commit f861fc8

Please sign in to comment.