Manual Compaction of Service Fabric Actor Replicas

Published Sep 21 2021 06:08 AM 535 Views
Microsoft

The auto-compaction is not enabled by default . If you see the settings CompactionThresholdInMB mentioned at Deleting Actor is not freeing up the Disk space - Microsoft Tech Community

 

  • CompactionThresholdInMB (type: Integer, default value: 0, valid range: >= 0): Compaction is performed only when physical DB size >= CompactionThresholdInMB. Auto-compaction can be disabled through setting CompactionThresholdInMB to a value <= 0.

However to enable the auto-compaction, the prior requirement is to have disk space, that is adequate disk space should be present on the node to enable the auto-compaction i.e. if you bloated size of the replica is showing 100 GB then you will need twice the amount of disk space to be free for auto-compaction to be enabled, that is additional 100 GB should be free. 

 

if you don't have adequate space and DB are bloated or you don't want to enable auto-compaction then you may consider performing manual compaction of the replicas/DB. 

 

In this we perform the logical build to compact . The logical build replica doesn’t have the physical size it only contains the actual data, once secondary logical build is completed, it is swapped with primary and then other replica is built from new primary and other bloated replica are discarded/ dropped. 

 

Below are steps to perform manual compaction. 

 

IMPORTANT NOTE : Never kill the primary. 

  • Find node name of primary using Service Fabric Desktop Explorer.
  • RDP into the primary node.
  • Change settings:
    • Go to W:\<Primary_Node_Name>\Fabric\
    • Open Fabric.Package.Current.xml file
    • Open settings.xml under Fabric.Config.CONFIG_FOLDER_VALUE/settings.xml under Fabric folder.
  • Update settings:
    • Similar to EseStoreSettings add or find a section with ReplicatorSettings
      <ConfigPackage Name="Fabric.Config" Version="{{CONFIG_FOLDER_VALUE}}" />
          <Section Name="ReplicatedStore">
              <Parameter Name="EnableFileStreamFullCopy" Value="false" />
          </Section>
      
  • Edit Fabric.Package.Current.xml to add a space.
    • Editing triggers the dynamic update on the property.
  • Start a new replica build :
    • If there is an existing inbuild/down/bad state replica, remove it using Remove-ServiceFabricReplica**. This should trigger new replica build by logical way.
    • If there are targetReplicaSetSize > minReplicaSetSize number of replicas, and you have targetrelicasetsize good replicas, then remove one of the active secondary. This should trigger a replica build by logical way.
    • Otherwise, increase targetreplicasetsize by 1 using Update-ServiceFabricService**
  • Confirm logical build is going on :
    • Using SFX, find the new node where new secondary replica is building.
    • RDP to new secondary replica and find new replica folder like here on this machine.
    • You should see that db file size is growing. This is logical copy way.

Important

  • While replica build is going on, Revert the settings in first settings.xml and then remove space from Fabric.Package.Current.xml so that we don't impact other replicas.

  • Keep checking SFX in 5 min interval when replica build is done.

  • Once you have an active secondary with compacted or logically build db, then just follow steps (2) and (3) to move primary and create new replicas using compacted/logically build primary.

  • ReplicaFolder:

    • Under W:\Apps\ folder, search for "P_<Partition_Id>" in explorer.
    • Open P_<Partition_Id> folder location : W:\Apps&lt;AppName>\work\P_<Parition_Id>.
    • Make sure there is R_<ReplicaId> folder here. Lets call this folder ReplicaFolder
  1. Steps to make new compacted secondary as Primary:

    • When compaction is done, compacted replica will come up and join the replica set size as new secondary. Either standby or active.
    • If compacted secondary is standby,
      • Then Primary must already be building a new secondary which would be inbuild.
        • Remove the inbuild replica using Remove-ServiceFabricReplica** cmdlet. This will force SF to make the compacted standby replica an active secondary.
      • If not, then remove any active secondary using Remove-ServiceFabricReplica ** cmdlet. Make sure there are target-set - 1 ready replicas including primary before this.
    • Once compacted secondary becomes active,
      • Call Move-ServiceFabricPrimaryReplica that will make compacted secondary as new primary.
  2. Steps to build new compacted secondaries from compacted primary:

    • Call Remove-ServiceFaricReplica on down/inbuild/active secondary
    • SF will automatically trigger a new replica build.
    • Unless this new replica is up and you have checked by looking at corresponding replica_folder, don't perform Remove-ServiceFabricReplica** on other secondaries
    • Once new compacted secondary is up, follow similar steps for other secondary.
    • Move-ServiceFabricPrimaryReplica -PartitionId <PARTITION_ID> -NodeName "<SECONDARY_REPLICA_NODE_NAME>" -ServiceName <SERVICE_NAME>
    • Remove-ServiceFabricReplica -NodeName "<SECONDARY_REPLICA_TO_REMOVE_NODE>" -PartitionId <PARTITION_ID> -ReplicaOrInstanceId <SECONDARY_REPLICA_ID>
%3CLINGO-SUB%20id%3D%22lingo-sub-2748124%22%20slang%3D%22en-US%22%3EManual%20Compaction%20of%20Service%20Fabric%20Actor%20Replicas%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2748124%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20auto-compaction%20is%20not%20enabled%20by%20default%20.%20If%20you%20see%20the%20settings%26nbsp%3BCompactionThresholdInMB%20mentioned%20at%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-paas-blog%2Fdeleting-actor-is-not-freeing-up-the-disk-space%2Fba-p%2F1607306%22%20target%3D%22_blank%22%3EDeleting%20Actor%20is%20not%20freeing%20up%20the%20Disk%20space%20-%20Microsoft%20Tech%20Community%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ECompactionThresholdInMB%20(type%3A%20Integer%2C%20%3CSTRONG%3Edefault%20value%3A%200%3C%2FSTRONG%3E%2C%20valid%20range%3A%20%26gt%3B%3D%200)%3A%20Compaction%20is%20performed%20only%20when%20physical%20DB%20size%20%26gt%3B%3D%26nbsp%3B%3CEM%3ECompactionThresholdInMB%3C%2FEM%3E.%20%3CSTRONG%3EAuto-compaction%20can%20be%20disabled%20through%20setting%26nbsp%3B%3CEM%3ECompactionThresholdInMB%3C%2FEM%3E%26nbsp%3Bto%20a%20value%20%26lt%3B%3D%200.%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EHowever%20to%20enable%20the%20auto-compaction%2C%20the%20prior%20requirement%20is%20to%20have%20disk%20space%2C%20that%20is%20adequate%20disk%20space%20should%20be%20present%20on%20the%20node%20to%20enable%20the%20auto-compaction%20i.e.%20if%20you%20bloated%20size%20of%20the%20replica%20is%20showing%20100%20GB%20then%20you%20will%20need%20twice%20the%20amount%20of%20disk%20space%20to%20be%20free%20for%20auto-compaction%20to%20be%20enabled%2C%20that%20is%20additional%20100%20GB%20should%20be%20free.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eif%20you%20don't%20have%20adequate%20space%20and%20DB%20are%20bloated%20or%20you%20don't%20want%20to%20enable%20auto-compaction%20then%20you%20may%20consider%20performing%20manual%20compaction%20of%20the%20replicas%2FDB.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20this%20we%20perform%20the%20logical%20build%20to%20compact%20.%20The%20logical%20build%20replica%20doesn%E2%80%99t%20have%20the%20physical%20size%20it%20only%20contains%20the%20actual%20data%2C%20once%20secondary%20logical%20build%20is%20completed%2C%20it%20is%20swapped%20with%20primary%20and%20then%20other%20replica%20is%20built%20from%20new%20primary%20and%20other%20bloated%20replica%20are%20discarded%2F%20dropped.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBelow%20are%20steps%20to%20perform%20manual%20compaction.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIMPORTANT%20NOTE%20%3A%20Never%20kill%20the%20primary.%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EFind%20node%20name%20of%20primary%20using%20Service%20Fabric%20Desktop%20Explorer.%3C%2FLI%3E%0A%3CLI%3ERDP%20into%20the%20primary%20node.%3C%2FLI%3E%0A%3CLI%3EChange%20settings%3A%3CUL%3E%0A%3CLI%3EGo%20to%20W%3A%5C%3CPRIMARY_NODE_NAME%3E%5CFabric%5C%3C%2FPRIMARY_NODE_NAME%3E%3C%2FLI%3E%0A%3CLI%3EOpen%20Fabric.Package.Current.xml%20file%3C%2FLI%3E%0A%3CLI%3EOpen%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3Esettings.xml%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eunder%20Fabric.Config.CONFIG_FOLDER_VALUE%2Fsettings.xml%20under%20Fabric%20folder.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3EUpdate%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3Esettings%3C%2FSPAN%3E%3A%3CUL%3E%0A%3CLI%3ESimilar%20to%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EEseStoreSettings%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eadd%20or%20find%20a%20section%20with%20ReplicatorSettings%3CPRE%3E%3CCODE%20class%3D%22hljs%20language-xml%22%3E%3CSPAN%20class%3D%22hljs-tag%22%3E%26lt%3B%3CSPAN%20class%3D%22hljs-name%22%3EConfigPackage%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EName%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22Fabric.Config%22%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EVersion%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22%7B%7BCONFIG_FOLDER_VALUE%7D%7D%22%3C%2FSPAN%3E%20%2F%26gt%3B%3C%2FSPAN%3E%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-tag%22%3E%26lt%3B%3CSPAN%20class%3D%22hljs-name%22%3ESection%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EName%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22ReplicatedStore%22%3C%2FSPAN%3E%26gt%3B%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-tag%22%3E%26lt%3B%3CSPAN%20class%3D%22hljs-name%22%3EParameter%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EName%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22EnableFileStreamFullCopy%22%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attr%22%3EValue%3C%2FSPAN%3E%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22false%22%3C%2FSPAN%3E%20%2F%26gt%3B%3C%2FSPAN%3E%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-tag%22%3ESection%3C%2FSPAN%3E%26gt%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3EEdit%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EFabric.Package.Current.xml%20to%20add%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3Espace%3C%2FSPAN%3E.%3CUL%3E%0A%3CLI%3EEditing%20triggers%20the%20dynamic%20update%20on%20the%20property.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3EStart%20a%20new%20replica%20build%20%3A%3CUL%3E%0A%3CLI%3EIf%20there%20is%20an%20existing%20inbuild%2Fdown%2Fbad%20state%20replica%2C%20remove%20it%20using%20Remove-ServiceFabricReplica**.%20This%20should%20trigger%20new%20replica%20build%20by%20logical%20way.%3C%2FLI%3E%0A%3CLI%3EIf%20there%20are%20targetReplicaSetSize%20%26gt%3B%20minReplicaSetSize%20number%20of%20replicas%2C%20and%20you%20have%20targetrelicasetsize%20good%20replicas%2C%20then%20remove%20one%20of%20the%20active%20secondary.%20This%20should%20trigger%20a%20replica%20build%20by%20logical%20way.%3C%2FLI%3E%0A%3CLI%3EOtherwise%2C%20increase%20targetreplicasetsize%20by%201%20using%20Update-ServiceFabricService**%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3EConfirm%20logical%20build%20is%20going%20on%20%3A%3CUL%3E%0A%3CLI%3EUsing%20SFX%2C%20find%20the%20new%20node%20where%20new%20secondary%20replica%20is%20building.%3C%2FLI%3E%0A%3CLI%3ERDP%20to%20new%20secondary%20replica%20and%20find%20new%20replica%20folder%20like%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3Ehere%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eon%20this%20machine.%3C%2FLI%3E%0A%3CLI%3EYou%20should%20see%20that%20db%20file%20size%20is%20growing.%20This%20is%20logical%20copy%20way.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH2%20id%3D%22important%22%20id%3D%22toc-hId--353254358%22%20id%3D%22toc-hId--350721192%22%3EImportant%3C%2FH2%3E%0A%3CUL%3E%0A%3CLI%3E%3CP%3EWhile%20replica%20build%20is%20going%20on%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3ERevert%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ethe%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3Esettings%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ein%20first%20settings.xml%20and%20then%20remove%20space%20from%20Fabric.Package.Current.xml%20so%20that%20we%20don't%20impact%20other%20replicas.%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CP%3EKeep%20checking%20SFX%20in%205%20min%20interval%20when%20replica%20build%20is%20done.%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CP%3EOnce%20you%20have%20an%20active%20secondary%20with%20compacted%20or%20logically%20build%20db%2C%20then%20just%20follow%20steps%20(2)%20and%20(3)%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20move%20primary%20and%20create%20new%20replicas%20using%20compacted%2Flogically%20build%20primary.%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CP%3E%3CSPAN%3EReplicaFolder%3C%2FSPAN%3E%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EUnder%20W%3A%5CApps%5C%20folder%2C%20search%20for%20%22P_%3CPARTITION_ID%3E%22%20in%20explorer.%3C%2FPARTITION_ID%3E%3C%2FLI%3E%0A%3CLI%3EOpen%20P_%3CPARTITION_ID%3E%20folder%20location%20%3A%20W%3A%5CApps%26amp%3Blt%3B%3CSPAN%3EAppName%3C%2FSPAN%3E%26gt%3B%5Cwork%5CP_%3CPARITION_ID%3E.%3C%2FPARITION_ID%3E%3C%2FPARTITION_ID%3E%3C%2FLI%3E%0A%3CLI%3EMake%20sure%20there%20is%20R_%3CREPLICAID%3E%20folder%20here.%20Lets%20call%20this%20folder%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EReplicaFolder%3C%2FSPAN%3E%3C%2FREPLICAID%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3COL%3E%0A%3CLI%3E%3CP%3ESteps%20to%20make%20new%20compacted%20secondary%20as%20Primary%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EWhen%20compaction%20is%20done%2C%20compacted%20replica%20will%20come%20up%20and%20join%20the%20replica%20set%20size%20as%20new%20secondary.%20Either%20standby%20or%20active.%3C%2FLI%3E%0A%3CLI%3EIf%20compacted%20secondary%20is%20standby%2C%3CUL%3E%0A%3CLI%3EThen%20Primary%20must%20already%20be%20building%20a%20new%20secondary%20which%20would%20be%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Einbuild%3C%2FCODE%3E.%3CUL%3E%0A%3CLI%3ERemove%20the%20inbuild%20replica%20using%20Remove-ServiceFabricReplica**%20cmdlet.%20This%20will%20force%20SF%20to%20make%20the%20compacted%20standby%20replica%20an%20active%20secondary.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3EIf%20not%2C%20then%20remove%20any%20active%20secondary%20using%20Remove-ServiceFabricReplica%20**%20cmdlet.%20Make%20sure%20there%20are%20target-set%20-%201%20ready%20replicas%20including%20primary%20before%20this.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3EOnce%20compacted%20secondary%20becomes%20active%2C%3CUL%3E%0A%3CLI%3ECall%20Move-ServiceFabricPrimaryReplica%20that%20will%20make%20compacted%20secondary%20as%20new%20primary.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CP%3ESteps%20to%20build%20new%20compacted%20secondaries%20from%20compacted%20primary%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ECall%20Remove-ServiceFaricReplica%20on%20down%2Finbuild%2Factive%20secondary%3C%2FLI%3E%0A%3CLI%3ESF%20will%20automatically%20trigger%20a%20new%20replica%20build.%3C%2FLI%3E%0A%3CLI%3EUnless%20this%20new%20replica%20is%20up%20and%20you%20have%20checked%20by%20looking%20at%20corresponding%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3Ereplica_folder%3C%2FSPAN%3E%2C%20don't%20perform%20Remove-ServiceFabricReplica**%20on%20other%20secondaries%3C%2FLI%3E%0A%3CLI%3EOnce%20new%20compacted%20secondary%20is%20up%2C%20follow%20similar%20steps%20for%20other%20secondary.%3C%2FLI%3E%0A%3CLI%3EMove-ServiceFabricPrimaryReplica%20-PartitionId%20%3CPARTITION_ID%3E%20-NodeName%20%22%3CSECONDARY_REPLICA_NODE_NAME%3E%22%20-ServiceName%20%3CSERVICE_NAME%3E%3C%2FSERVICE_NAME%3E%3C%2FSECONDARY_REPLICA_NODE_NAME%3E%3C%2FPARTITION_ID%3E%3C%2FLI%3E%0A%3CLI%3ERemove-ServiceFabricReplica%20-NodeName%20%22%3CSECONDARY_REPLICA_TO_REMOVE_NODE%3E%22%20-PartitionId%20%3CPARTITION_ID%3E%20-ReplicaOrInstanceId%20%3CSECONDARY_REPLICA_ID%3E%3C%2FSECONDARY_REPLICA_ID%3E%3C%2FPARTITION_ID%3E%3C%2FSECONDARY_REPLICA_TO_REMOVE_NODE%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2748124%22%20slang%3D%22en-US%22%3E%3CP%3ESteps%20to%20perform%20logical%20build%2F%20manual%20compaction%20of%20bloated%20KVS%2FDatabases%20in%20Actor%3C%2FP%3E%3C%2FLINGO-TEASER%3E
Co-Authors
Version history
Last update:
‎Sep 21 2021 06:08 AM
Updated by:
www.000webhost.com