-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pump client: add compatible with kafka version && refine retry && add…
… strategy config (#223) * pump client: compatible with kafka version tidb-binlog && add unit test (#139) * pump client: write commit binlog will never return error (#148) * pkg watcher: move watcher from tidb-enterprise-tools (#146) * pump client: increase retry time, and refine some code (#158) * pump client: add initial log function (#165) * pump client: support change select pump's strategy (#221)
- Loading branch information
1 parent
419f308
commit 64d87c4
Showing
14 changed files
with
1,287 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package watcher | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
) | ||
|
||
// Op represents file operation type | ||
type Op uint32 | ||
|
||
// Operations type current supported | ||
const ( | ||
Create Op = 1 << iota | ||
Remove | ||
Modify | ||
Rename | ||
Chmod | ||
Move | ||
) | ||
|
||
func (op Op) String() string { | ||
var buffer bytes.Buffer | ||
|
||
// now, only one Op will used in polling, but it can combine multi Ops if needed | ||
if op&Create == Create { | ||
buffer.WriteString("|CREATE") | ||
} | ||
if op&Remove == Remove { | ||
buffer.WriteString("|REMOVE") | ||
} | ||
if op&Modify == Modify { | ||
buffer.WriteString("|MODIFY") | ||
} | ||
if op&Rename == Rename { | ||
buffer.WriteString("|RENAME") | ||
} | ||
if op&Chmod == Chmod { | ||
buffer.WriteString("|CHMOD") | ||
} | ||
if op&Move == Move { | ||
buffer.WriteString("|MOVE") | ||
} | ||
if buffer.Len() == 0 { | ||
return "" | ||
} | ||
return buffer.String()[1:] // Strip leading pipe | ||
} | ||
|
||
// Event represents a single file operation event | ||
type Event struct { | ||
Path string | ||
Op Op | ||
FileInfo os.FileInfo | ||
} | ||
|
||
// IsDirEvent returns whether is a event for a directory | ||
func (e *Event) IsDirEvent() bool { | ||
if e == nil { | ||
return false | ||
} | ||
return e.FileInfo.IsDir() | ||
} | ||
|
||
// HasOps checks whether has any specified operation types | ||
func (e *Event) HasOps(ops ...Op) bool { | ||
if e == nil { | ||
return false | ||
} | ||
for _, op := range ops { | ||
if e.Op&op != 0 { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
Oops, something went wrong.