-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#11150] Add WAL durability setting to collector
- Loading branch information
Showing
4 changed files
with
119 additions
and
2 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
50 changes: 50 additions & 0 deletions
50
collector/src/main/java/com/navercorp/pinpoint/collector/util/DurabilityApplier.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,50 @@ | ||
package com.navercorp.pinpoint.collector.util; | ||
|
||
import com.navercorp.pinpoint.common.util.StringUtils; | ||
import org.apache.hadoop.hbase.client.Durability; | ||
import org.apache.hadoop.hbase.client.Mutation; | ||
|
||
import java.util.Objects; | ||
|
||
public class DurabilityApplier { | ||
private final Durability durability; | ||
|
||
public DurabilityApplier(String durability) { | ||
this(durability, Durability.USE_DEFAULT); | ||
} | ||
|
||
public DurabilityApplier(String durability, Durability defaultDurability) { | ||
this.durability = toDurability(durability, defaultDurability); | ||
} | ||
|
||
public static Durability toDurability(String durability, Durability defaultDurability) { | ||
Objects.requireNonNull(defaultDurability, "defaultDurability"); | ||
|
||
if (StringUtils.isEmpty(durability)) { | ||
return defaultDurability; | ||
} | ||
try { | ||
return Durability.valueOf(durability.toUpperCase()); | ||
} catch (IllegalArgumentException e) { | ||
return defaultDurability; | ||
} | ||
} | ||
|
||
public void apply(Mutation mutation) { | ||
if (mutation == null) { | ||
return; | ||
} | ||
mutation.setDurability(durability); | ||
} | ||
|
||
public Durability getDurability() { | ||
return durability; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DurabilityConfiguration{" + | ||
"durability=" + durability + | ||
'}'; | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
collector/src/test/java/com/navercorp/pinpoint/collector/util/DurabilityApplierTest.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,45 @@ | ||
package com.navercorp.pinpoint.collector.util; | ||
|
||
import org.apache.hadoop.hbase.client.Durability; | ||
import org.apache.hadoop.hbase.client.Put; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class DurabilityApplierTest { | ||
|
||
@Test | ||
void null_to_default() { | ||
DurabilityApplier config = new DurabilityApplier(null); | ||
assertEquals(Durability.USE_DEFAULT, config.getDurability()); | ||
} | ||
|
||
@Test | ||
void skipwal() { | ||
DurabilityApplier config = new DurabilityApplier("SKIP_WAL"); | ||
assertEquals(Durability.SKIP_WAL, config.getDurability()); | ||
} | ||
|
||
@Test | ||
void skipwal_uppercase() { | ||
DurabilityApplier configuration = new DurabilityApplier("skip_wal"); | ||
assertEquals(Durability.SKIP_WAL, configuration.getDurability()); | ||
} | ||
|
||
@Test | ||
void skipwal_unknown() { | ||
DurabilityApplier configuration = new DurabilityApplier("unknown"); | ||
assertEquals(Durability.USE_DEFAULT, configuration.getDurability()); | ||
} | ||
|
||
|
||
@Test | ||
void testPut() { | ||
Put put = new Put(new byte[1]); | ||
|
||
DurabilityApplier applier = new DurabilityApplier(Durability.SKIP_WAL.toString()); | ||
applier.apply(put); | ||
|
||
assertEquals(Durability.SKIP_WAL, put.getDurability()); | ||
} | ||
} |