Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dgraph
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
dgraph
Commits
ff5374de
Commit
ff5374de
authored
9 years ago
by
Manish R Jain
Browse files
Options
Downloads
Patches
Plain Diff
Log write, rotate and reload works.
parent
74cabf90
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
commit/log.go
+22
-16
22 additions, 16 deletions
commit/log.go
commit/log_test.go
+5
-3
5 additions, 3 deletions
commit/log_test.go
with
27 additions
and
19 deletions
commit/log.go
+
22
−
16
View file @
ff5374de
...
...
@@ -152,22 +152,6 @@ func (l *Logger) handleFile(path string, info os.FileInfo, err error) error {
// Handle if we find the current log file.
if
tstring
==
"current"
{
var
err
error
l
.
size
=
info
.
Size
()
l
.
curFile
,
err
=
os
.
OpenFile
(
path
,
os
.
O_APPEND
|
os
.
O_WRONLY
,
os
.
FileMode
(
0644
))
if
err
!=
nil
{
glog
.
WithError
(
err
)
.
Fatal
(
"Unable to open file in write mode."
)
}
/*
ret, err := l.curFile.Seek(info.Size(), 0)
if err != nil || ret != info.Size() {
glog.WithError(err).Fatal("Unable to seek to end of file.")
}
*/
l
.
lastLogTs
,
err
=
lastTimestamp
(
path
)
if
err
!=
nil
{
glog
.
WithError
(
err
)
.
Fatal
(
"Unable to read last log timestamp."
)
}
return
nil
}
...
...
@@ -186,6 +170,28 @@ func (l *Logger) Init() {
l
.
Lock
()
defer
l
.
Unlock
()
{
// First check if we have a current file.
path
:=
filepath
.
Join
(
l
.
dir
,
fmt
.
Sprintf
(
"%s-current.log"
,
l
.
filePrefix
))
fi
,
err
:=
os
.
Stat
(
path
)
if
err
==
nil
{
// we have the file. Derive information for counters.
l
.
size
=
fi
.
Size
()
l
.
logsSinceLastSync
=
0
l
.
lastLogTs
,
err
=
lastTimestamp
(
path
)
if
err
!=
nil
{
glog
.
WithError
(
err
)
.
Fatal
(
"Unable to read last log timestamp."
)
}
// Open file for append.
l
.
curFile
,
err
=
os
.
OpenFile
(
path
,
os
.
O_APPEND
|
os
.
O_WRONLY
,
os
.
FileMode
(
0644
))
if
err
!=
nil
{
glog
.
WithError
(
err
)
.
Fatal
(
"Unable to open current file in append mode."
)
}
}
}
if
err
:=
filepath
.
Walk
(
l
.
dir
,
l
.
handleFile
);
err
!=
nil
{
glog
.
WithError
(
err
)
.
Fatal
(
"While walking over directory"
)
}
...
...
This diff is collapsed.
Click to expand it.
commit/log_test.go
+
5
−
3
View file @
ff5374de
...
...
@@ -129,29 +129,31 @@ func TestRotatingLog(t *testing.T) {
t
.
Errorf
(
"Expected ts: %v. Got: %v"
,
ts
+
int64
(
8
),
l
.
lastLogTs
)
}
l
.
Close
()
l
=
nil
// Important to avoid re-use later.
// Now, let's test a re-init of logger.
nl
:=
NewLogger
(
dir
,
"dgraph"
,
1024
)
nl
.
Init
()
defer
nl
.
Close
()
if
len
(
nl
.
list
)
!=
4
{
t
.
Errorf
(
"Expected 4 files. Got: %v"
,
len
(
nl
.
list
))
}
if
nl
.
size
!=
416
{
t
.
Errorf
(
"Expected size 416. Got: %v"
,
nl
.
size
)
}
if
err
:=
l
.
AddLog
(
ts
+
int64
(
100
),
0
,
data
);
err
!=
nil
{
if
err
:=
n
l
.
AddLog
(
ts
+
int64
(
100
),
0
,
data
);
err
!=
nil
{
t
.
Error
(
err
)
return
}
if
nl
.
size
!=
832
{
t
.
Errorf
(
"Expected size 832. Got: %v"
,
nl
.
size
)
}
if
err
:=
l
.
AddLog
(
ts
+
int64
(
113
),
0
,
data
);
err
!=
nil
{
if
err
:=
n
l
.
AddLog
(
ts
+
int64
(
113
),
0
,
data
);
err
!=
nil
{
t
.
Error
(
err
)
return
}
if
len
(
nl
.
list
)
!=
5
{
t
.
Errorf
(
"Expected
4
files. Got: %v"
,
len
(
nl
.
list
))
t
.
Errorf
(
"Expected
5
files. Got: %v"
,
len
(
nl
.
list
))
}
if
nl
.
list
[
4
]
.
endTs
!=
ts
+
int64
(
100
)
{
t
.
Errorf
(
"Expected ts: %v. Got: %v"
,
ts
+
int64
(
100
),
nl
.
list
[
4
]
.
endTs
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment