Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
5115f0e6
Commit
5115f0e6
authored
Jun 02, 2015
by
Brian Grant
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8888 from smarterclayton/add_new_allocators
Add a new contiguous allocator strategy option
parents
e77ded1e
e89d5518
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
2 deletions
+39
-2
bitmap.go
pkg/registry/service/allocator/bitmap.go
+38
-0
allocator.go
pkg/registry/service/portallocator/allocator.go
+1
-2
No files found.
pkg/registry/service/allocator/bitmap.go
View file @
5115f0e6
...
@@ -55,6 +55,7 @@ var _ Snapshottable = &AllocationBitmap{}
...
@@ -55,6 +55,7 @@ var _ Snapshottable = &AllocationBitmap{}
// allocateStrategy is a search strategy in the allocation map for a valid item.
// allocateStrategy is a search strategy in the allocation map for a valid item.
type
allocateStrategy
func
(
allocated
*
big
.
Int
,
max
,
count
int
)
(
int
,
bool
)
type
allocateStrategy
func
(
allocated
*
big
.
Int
,
max
,
count
int
)
(
int
,
bool
)
// NewAllocationMap creates an allocation bitmap using the random scan strategy.
func
NewAllocationMap
(
max
int
,
rangeSpec
string
)
*
AllocationBitmap
{
func
NewAllocationMap
(
max
int
,
rangeSpec
string
)
*
AllocationBitmap
{
a
:=
AllocationBitmap
{
a
:=
AllocationBitmap
{
strategy
:
randomScanStrategy
,
strategy
:
randomScanStrategy
,
...
@@ -66,6 +67,30 @@ func NewAllocationMap(max int, rangeSpec string) *AllocationBitmap {
...
@@ -66,6 +67,30 @@ func NewAllocationMap(max int, rangeSpec string) *AllocationBitmap {
return
&
a
return
&
a
}
}
// NewContiguousAllocationMap creates an allocation bitmap using the contiguous scan strategy.
func
NewContiguousAllocationMap
(
max
int
,
rangeSpec
string
)
*
AllocationBitmap
{
a
:=
AllocationBitmap
{
strategy
:
contiguousScanStrategy
,
allocated
:
big
.
NewInt
(
0
),
count
:
0
,
max
:
max
,
rangeSpec
:
rangeSpec
,
}
return
&
a
}
// NewRandomAllocationInterface creates an allocation bitmap satisfying Interface using the
// random scan strategy.
func
NewRandomAllocationInterface
(
max
int
,
rangeSpec
string
)
Interface
{
return
NewAllocationMap
(
max
,
rangeSpec
)
}
// NewContiguousAllocationInterface creates an allocation bitmap satisfying Interface using the
// contiguous scan strategy.
func
NewContiguousAllocationInterface
(
max
int
,
rangeSpec
string
)
Interface
{
return
NewContiguousAllocationMap
(
max
,
rangeSpec
)
}
// Allocate attempts to reserve the provided item.
// Allocate attempts to reserve the provided item.
// Returns true if it was allocated, false if it was already in use
// Returns true if it was allocated, false if it was already in use
func
(
r
*
AllocationBitmap
)
Allocate
(
offset
int
)
(
bool
,
error
)
{
func
(
r
*
AllocationBitmap
)
Allocate
(
offset
int
)
(
bool
,
error
)
{
...
@@ -166,3 +191,16 @@ func randomScanStrategy(allocated *big.Int, max, count int) (int, bool) {
...
@@ -166,3 +191,16 @@ func randomScanStrategy(allocated *big.Int, max, count int) (int, bool) {
}
}
return
0
,
false
return
0
,
false
}
}
// contiguousScanStrategy tries to allocate starting at 0 and filling in any gaps
func
contiguousScanStrategy
(
allocated
*
big
.
Int
,
max
,
count
int
)
(
int
,
bool
)
{
if
count
>=
max
{
return
0
,
false
}
for
i
:=
0
;
i
<
max
;
i
++
{
if
allocated
.
Bit
(
i
)
==
0
{
return
i
,
true
}
}
return
0
,
false
}
pkg/registry/service/portallocator/allocator.go
View file @
5115f0e6
...
@@ -151,8 +151,7 @@ func (r *PortAllocator) Restore(pr util.PortRange, data []byte) error {
...
@@ -151,8 +151,7 @@ func (r *PortAllocator) Restore(pr util.PortRange, data []byte) error {
if
!
ok
{
if
!
ok
{
return
fmt
.
Errorf
(
"not a snapshottable allocator"
)
return
fmt
.
Errorf
(
"not a snapshottable allocator"
)
}
}
snapshottable
.
Restore
(
pr
.
String
(),
data
)
return
snapshottable
.
Restore
(
pr
.
String
(),
data
)
return
nil
}
}
// contains returns true and the offset if the port is in the range, and false
// contains returns true and the offset if the port is in the range, and false
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment