diff --git a/src/Soil-Core/SoilBasicBTree.class.st b/src/Soil-Core/SoilBasicBTree.class.st index cb501303..0e38bb8e 100644 --- a/src/Soil-Core/SoilBasicBTree.class.st +++ b/src/Soil-Core/SoilBasicBTree.class.st @@ -29,6 +29,11 @@ SoilBasicBTree >> flush [ self store flush ] +{ #category : #testing } +SoilBasicBTree >> hasHeaderPage [ + ^ store hasHeaderPage +] + { #category : #initialization } SoilBasicBTree >> initializeFilesystem [ self store initializeFilesystem diff --git a/src/Soil-Core/SoilBasicSkipList.class.st b/src/Soil-Core/SoilBasicSkipList.class.st index c9507ab9..57aae17a 100644 --- a/src/Soil-Core/SoilBasicSkipList.class.st +++ b/src/Soil-Core/SoilBasicSkipList.class.st @@ -17,6 +17,11 @@ SoilBasicSkipList class >> isAbstract [ ^ self == SoilBasicSkipList ] +{ #category : #testing } +SoilBasicSkipList >> hasHeaderPage [ + ^ store hasHeaderPage +] + { #category : #accessing } SoilBasicSkipList >> maxLevel [ diff --git a/src/Soil-Core/SoilPagedIndexStore.class.st b/src/Soil-Core/SoilPagedIndexStore.class.st index a2843b32..e6125670 100644 --- a/src/Soil-Core/SoilPagedIndexStore.class.st +++ b/src/Soil-Core/SoilPagedIndexStore.class.st @@ -25,6 +25,11 @@ SoilPagedIndexStore >> flushCachedPages [ pages removeAll ] +{ #category : #testing } +SoilPagedIndexStore >> hasHeaderPage [ + ^ pages includesKey: 1 +] + { #category : #accessing } SoilPagedIndexStore >> headerPage [ ^ self pageAt: 1 diff --git a/src/Soil-Core/SoilReindexer.class.st b/src/Soil-Core/SoilReindexer.class.st index cf73c47c..660102ca 100644 --- a/src/Soil-Core/SoilReindexer.class.st +++ b/src/Soil-Core/SoilReindexer.class.st @@ -67,12 +67,14 @@ SoilReindexer >> prepareNewIndex [ | indexCopy | indexCopy := index class new path: reIndexPath; - initializeFilesystem; - initializeHeaderPage; - maxLevel: index maxLevel; - keySize: index keySize; - valueSize: index valueSize. - newIndex := indexBlock value: indexCopy + initializeFilesystem. + newIndex := indexBlock value: indexCopy. + newIndex hasHeaderPage ifFalse: [ + newIndex + initializeHeaderPage; + maxLevel: index maxLevel; + keySize: index keySize; + valueSize: index valueSize ] ] { #category : #running } diff --git a/src/Soil-Core/SoilSkipList.class.st b/src/Soil-Core/SoilSkipList.class.st index 92f973a7..70c4e482 100644 --- a/src/Soil-Core/SoilSkipList.class.st +++ b/src/Soil-Core/SoilSkipList.class.st @@ -82,6 +82,7 @@ SoilSkipList >> newHeaderPage [ ^ SoilSkipListHeaderPage new index: 1; lastPageIndex: 1; + lastFreePageIndex: 0; pageSize: self pageSize ] diff --git a/src/Soil-Core/SoilSkipListHeaderPage.class.st b/src/Soil-Core/SoilSkipListHeaderPage.class.st index c583e92a..18795f2c 100644 --- a/src/Soil-Core/SoilSkipListHeaderPage.class.st +++ b/src/Soil-Core/SoilSkipListHeaderPage.class.st @@ -16,7 +16,8 @@ Class { #superclass : #SoilSkipListPage, #instVars : [ 'maxLevel', - 'lastPageIndex' + 'lastPageIndex', + 'lastFreePageIndex' ], #category : #'Soil-Core-Index-SkipList' } @@ -29,12 +30,19 @@ SoilSkipListHeaderPage class >> pageCode [ { #category : #utilities } SoilSkipListHeaderPage >> headerSize [ ^ super headerSize - + 10 "keySize, valueSize, maxLevel, lastPageIndex" + + 14 "keySize(2), valueSize(2), maxLevel(2), lastPageIndex(4), lastFreePageIndex(4)" + 1 "level" + (self level * self rightSize) + 2 "items size" ] +{ #category : #initialization } +SoilSkipListHeaderPage >> initialize [ + super initialize. + lastPageIndex := 1. + lastFreePageIndex := 0 +] + { #category : #accessing } SoilSkipListHeaderPage >> keySize: anInteger [ "as long as no items have been added the key size can be changed" @@ -46,6 +54,18 @@ SoilSkipListHeaderPage >> keySize: anInteger [ ] +{ #category : #accessing } +SoilSkipListHeaderPage >> lastFreePageIndex [ + + ^ lastFreePageIndex +] + +{ #category : #accessing } +SoilSkipListHeaderPage >> lastFreePageIndex: anObject [ + + lastFreePageIndex := anObject +] + { #category : #accessing } SoilSkipListHeaderPage >> lastPageIndex [ @@ -93,7 +113,8 @@ SoilSkipListHeaderPage >> readHeaderFrom: aStream [ keySize := (aStream next: 2) asInteger. valueSize := (aStream next: 2) asInteger. maxLevel := (aStream next: 2) asInteger. - lastPageIndex :=(aStream next: 4) asInteger + lastPageIndex :=(aStream next: 4) asInteger. + lastFreePageIndex :=(aStream next: 4) asInteger ] { #category : #accessing } @@ -108,7 +129,8 @@ SoilSkipListHeaderPage >> writeHeaderOn: aStream [ nextPutAll: (keySize asByteArrayOfSize: 2); nextPutAll: (valueSize asByteArrayOfSize: 2); nextPutAll: (maxLevel asByteArrayOfSize: 2); - nextPutAll: (lastPageIndex asByteArrayOfSize: 4). + nextPutAll: (lastPageIndex asByteArrayOfSize: 4); + nextPutAll: (lastFreePageIndex asByteArrayOfSize: 4). self writeLevelsOn: aStream. aStream nextPutAll: (items size asByteArrayOfSize: self itemsSizeSize).