Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
MKCLOS
Core Development Platform
coreospackage
Commits
396fca27
Commit
396fca27
authored
7 years ago
by
Ajit Jagtap
Browse files
Options
Downloads
Plain Diff
Merge branch 'LazyWriter_Min_Len_SSS' into 'master'
Lazywriter min data length changes See merge request
!32
parents
62fcfb03
92825222
Branches
Branches containing commit
1 merge request
!32
Lazywriter min data length changes
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dalhelper/lazywriter.go
+39
-2
dalhelper/lazywriter.go
with
39 additions
and
2 deletions
dalhelper/lazywriter.go
+
39
−
2
View file @
396fca27
...
...
@@ -17,6 +17,8 @@ import (
// var isDebugMode = false
var
lazyMutex
=
&
sync
.
Mutex
{}
const
MIN_DATA_LENGTH
=
10
// LazyFDPHelper Helps to Save and Get cache object
// also saves information into hard disk
type
LazyFDPHelper
struct
{
...
...
@@ -146,18 +148,37 @@ func (lfd *LazyFDPHelper) saveObjectsToFdb() {
}
// SaveOrUpdateDataInCache this method will Save object in cache if unavailable
func
(
lfd
*
LazyFDPHelper
)
SaveOrUpdateDataInCache
(
newObject
LazyCacheObject
)
{
func
(
lfd
*
LazyFDPHelper
)
SaveOrUpdateDataInCache
(
newObject
LazyCacheObject
)
bool
{
byteArray
,
marshalError
:=
ffjson
.
Marshal
(
newObject
.
InterfaceData
)
if
marshalError
!=
nil
{
logginghelper
.
LogError
(
"error occured while marshaling data "
,
marshalError
)
return
false
}
// check data length before saving. If less than assumed data length, return false
lengthOfData
:=
len
(
byteArray
)
if
lengthOfData
<
MIN_DATA_LENGTH
{
logginghelper
.
LogError
(
"data size is less than minimun expected data length. Actual data length: "
,
lengthOfData
)
logginghelper
.
LogError
(
"data received: "
,
string
(
byteArray
))
return
false
}
retryCount
:=
0
retrylabel
:
// Get prev object and then save new one
//TODO: catch errors
dataFromGC
,
getError
:=
lfd
.
gc
.
Get
(
newObject
.
FileName
)
if
getError
!=
nil
||
dataFromGC
==
nil
{
newObject
.
ChangeCount
=
1
lfd
.
gc
.
Set
(
newObject
.
FileName
,
newObject
)
}
else
{
oldObject
,
_
:=
dataFromGC
.
(
LazyCacheObject
)
if
oldObject
.
IsLocked
&&
retryCount
<
lfd
.
MAX_NUMBER_OF_RETRY
{
retryCount
++
...
...
@@ -176,20 +197,32 @@ retrylabel:
// lazyCacheObject.MEMORY_WRITE_COUNT++
// PerformanceAnalyser[newObject.FileName] = lazyCacheObject
// }
return
true
}
//saveDataToFDB data to hard disk.
// This saves data by marshaling using json.Marshal
func
saveDataToFDB
(
filePath
string
,
objectData
interface
{})
{
func
saveDataToFDB
(
filePath
string
,
objectData
interface
{})
bool
{
//TODO: catch errors
byteArray
,
marshalError
:=
ffjson
.
Marshal
(
objectData
)
if
marshalError
!=
nil
{
logginghelper
.
LogError
(
"error occured while marshaling data "
,
marshalError
)
return
false
}
// check data length before saving. If less than assumed data length, return false
lengthOfData
:=
len
(
byteArray
)
if
lengthOfData
<
MIN_DATA_LENGTH
{
logginghelper
.
LogError
(
"data size is less than minimun expected data length. Actual data length: "
,
lengthOfData
)
logginghelper
.
LogError
(
"data received: "
,
string
(
byteArray
))
return
false
}
saveError
:=
SaveDataToFDB
(
filePath
,
byteArray
,
true
)
if
saveError
!=
nil
{
logginghelper
.
LogError
(
"error occured while saving data "
,
saveError
)
return
false
}
return
true
}
// use it when req.
...
...
@@ -403,3 +436,7 @@ func appendDataToFDB(filePath string, objectData interface{}) {
logginghelper
.
LogError
(
"error occured while saving data "
,
saveError
)
}
}
func
Save
(
filePath
string
,
data
interface
{})
{
saveDataToFDB
(
filePath
,
data
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
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
Menu
Explore
Projects
Groups
Topics
Snippets