-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better usage control of node cache size #10782
- Loading branch information
Showing
17 changed files
with
168 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 4 additions & 81 deletions
85
modules/core/core-api/src/main/java/com/enonic/xp/util/ByteSizeParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,14 @@ | ||
package com.enonic.xp.util; | ||
|
||
import java.util.Locale; | ||
|
||
public class ByteSizeParser | ||
public final class ByteSizeParser | ||
{ | ||
|
||
private static final long BYTE_FACTOR = 1L; | ||
|
||
private static final long KB_FACTOR = BYTE_FACTOR * 1024L; | ||
|
||
private static final long MB_FACTOR = KB_FACTOR * 1024L; | ||
|
||
private static final long GB_FACTOR = MB_FACTOR * 1024L; | ||
|
||
private static final long TB_FACTOR = GB_FACTOR * 1024L; | ||
|
||
private static final long PB_FACTOR = TB_FACTOR * 1024L; | ||
|
||
public static long parse( final String sValue ) | ||
private ByteSizeParser() | ||
{ | ||
String postFix = sValue. | ||
substring( sValue.length() - Math.min( 2, sValue.length() ) ). | ||
toLowerCase( Locale.ROOT ); | ||
|
||
long bytes; | ||
|
||
if ( postFix.endsWith( "k" ) ) | ||
{ | ||
bytes = (long) parseByteValue( sValue, KB_FACTOR, 1 ); | ||
} | ||
else if ( postFix.endsWith( "kb" ) ) | ||
{ | ||
bytes = (long) ( parseByteValue( sValue, KB_FACTOR, 2 ) ); | ||
} | ||
else if ( postFix.endsWith( "m" ) ) | ||
{ | ||
bytes = (long) ( parseByteValue( sValue, MB_FACTOR, 1 ) ); | ||
} | ||
else if ( postFix.endsWith( "mb" ) ) | ||
{ | ||
bytes = (long) ( parseByteValue( sValue, MB_FACTOR, 2 ) ); | ||
} | ||
else if ( postFix.endsWith( "g" ) ) | ||
{ | ||
bytes = (long) ( parseByteValue( sValue, GB_FACTOR, 1 ) ); | ||
} | ||
else if ( postFix.endsWith( "gb" ) ) | ||
{ | ||
bytes = (long) ( parseByteValue( sValue, GB_FACTOR, 2 ) ); | ||
} | ||
else if ( postFix.endsWith( "t" ) ) | ||
{ | ||
bytes = (long) ( parseByteValue( sValue, TB_FACTOR, 1 ) ); | ||
} | ||
else if ( postFix.endsWith( "tb" ) ) | ||
{ | ||
bytes = (long) ( parseByteValue( sValue, TB_FACTOR, 2 ) ); | ||
} | ||
else if ( postFix.endsWith( "p" ) ) | ||
{ | ||
bytes = (long) ( parseByteValue( sValue, PB_FACTOR, 1 ) ); | ||
} | ||
else if ( postFix.endsWith( "pb" ) ) | ||
{ | ||
bytes = (long) ( parseByteValue( sValue, PB_FACTOR, 2 ) ); | ||
} | ||
else if ( postFix.endsWith( "b" ) ) | ||
{ | ||
bytes = Long.parseLong( sValue.substring( 0, sValue.length() - 1 ) ); | ||
} | ||
else | ||
{ | ||
bytes = Long.parseLong( sValue ); | ||
} | ||
|
||
return bytes; | ||
} | ||
|
||
private static double parseByteValue( final String sValue, final long kbFactor, final int postfixLenght ) | ||
public static long parse( final String sValue ) | ||
{ | ||
try | ||
{ | ||
return Double.parseDouble( sValue.substring( 0, sValue.length() - postfixLenght ) ) * kbFactor; | ||
} | ||
catch ( NumberFormatException e ) | ||
{ | ||
throw new IllegalArgumentException( "Wrong format of size-value [" + sValue + "]" ); | ||
} | ||
return com.enonic.xp.core.internal.ByteSizeParser.parse( sValue ); | ||
} | ||
} |
16 changes: 0 additions & 16 deletions
16
...ore-blobstore/src/main/java/com/enonic/xp/internal/blobstore/cache/BlobRecordWeigher.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
modules/core/core-internal/src/main/java/com/enonic/xp/core/internal/ByteSizeParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.enonic.xp.core.internal; | ||
|
||
import java.util.Locale; | ||
|
||
public final class ByteSizeParser | ||
{ | ||
|
||
private ByteSizeParser() | ||
{ | ||
} | ||
|
||
private static final long BYTE_FACTOR = 1L; | ||
|
||
private static final long KB_FACTOR = BYTE_FACTOR * 1024L; | ||
|
||
private static final long MB_FACTOR = KB_FACTOR * 1024L; | ||
|
||
private static final long GB_FACTOR = MB_FACTOR * 1024L; | ||
|
||
private static final long TB_FACTOR = GB_FACTOR * 1024L; | ||
|
||
private static final long PB_FACTOR = TB_FACTOR * 1024L; | ||
|
||
public static long parse( final String sValue ) | ||
{ | ||
String postFix = sValue. | ||
substring( sValue.length() - Math.min( 2, sValue.length() ) ). | ||
toLowerCase( Locale.ROOT ); | ||
|
||
long bytes; | ||
|
||
if ( postFix.endsWith( "k" ) ) | ||
{ | ||
bytes = (long) parseByteValue( sValue, KB_FACTOR, 1 ); | ||
} | ||
else if ( postFix.endsWith( "kb" ) ) | ||
{ | ||
bytes = (long) ( parseByteValue( sValue, KB_FACTOR, 2 ) ); | ||
} | ||
else if ( postFix.endsWith( "m" ) ) | ||
{ | ||
bytes = (long) ( parseByteValue( sValue, MB_FACTOR, 1 ) ); | ||
} | ||
else if ( postFix.endsWith( "mb" ) ) | ||
{ | ||
bytes = (long) ( parseByteValue( sValue, MB_FACTOR, 2 ) ); | ||
} | ||
else if ( postFix.endsWith( "g" ) ) | ||
{ | ||
bytes = (long) ( parseByteValue( sValue, GB_FACTOR, 1 ) ); | ||
} | ||
else if ( postFix.endsWith( "gb" ) ) | ||
{ | ||
bytes = (long) ( parseByteValue( sValue, GB_FACTOR, 2 ) ); | ||
} | ||
else if ( postFix.endsWith( "t" ) ) | ||
{ | ||
bytes = (long) ( parseByteValue( sValue, TB_FACTOR, 1 ) ); | ||
} | ||
else if ( postFix.endsWith( "tb" ) ) | ||
{ | ||
bytes = (long) ( parseByteValue( sValue, TB_FACTOR, 2 ) ); | ||
} | ||
else if ( postFix.endsWith( "p" ) ) | ||
{ | ||
bytes = (long) ( parseByteValue( sValue, PB_FACTOR, 1 ) ); | ||
} | ||
else if ( postFix.endsWith( "pb" ) ) | ||
{ | ||
bytes = (long) ( parseByteValue( sValue, PB_FACTOR, 2 ) ); | ||
} | ||
else if ( postFix.endsWith( "b" ) ) | ||
{ | ||
bytes = Long.parseLong( sValue.substring( 0, sValue.length() - 1 ) ); | ||
} | ||
else | ||
{ | ||
bytes = Long.parseLong( sValue ); | ||
} | ||
|
||
return bytes; | ||
} | ||
|
||
private static double parseByteValue( final String sValue, final long kbFactor, final int postfixLenght ) | ||
{ | ||
try | ||
{ | ||
return Double.parseDouble( sValue.substring( 0, sValue.length() - postfixLenght ) ) * kbFactor; | ||
} | ||
catch ( NumberFormatException e ) | ||
{ | ||
throw new IllegalArgumentException( "Wrong format of size-value [" + sValue + "]" ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...om/enonic/xp/util/ByteSizeParserTest.java → .../xp/core/internal/ByteSizeParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.enonic.xp.util; | ||
package com.enonic.xp.core.internal; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...ore/impl/image/MemoryLimitParserTest.java → .../core/internal/MemoryLimitParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ public interface RepoConfiguration | |
{ | ||
Path getSnapshotsDir(); | ||
|
||
int cacheSize(); | ||
String cacheCapacity(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.