Skip to content

Instantly share code, notes, and snippets.

@matteobertozzi
matteobertozzi / PriorityQueue.java
Created April 16, 2014 03:26
PriorityQueue that mantains the FIFO order when elements has same priority
import java.util.*;
public class TestPriorityQueue {
private static class HalfRingQ<E> {
private final Comparator<? super E> comparator;
private final E[] objects;
private int head = 0;
private int tail = 0;
@matteobertozzi
matteobertozzi / NamedLock.java
Created July 24, 2014 21:11
Simple Named Lock
private class NamedLock<T> {
private HashSet<T> locks = new HashSet<T>();
public void lock(final T name) {
synchronized (locks) {
while (locks.contains(name)) {
locks.wait();
}
locks.add(name);
}
@matteobertozzi
matteobertozzi / CVE-2014-3566.patch
Created November 13, 2014 16:22
HBase CVE-2014-3566
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java
index 9de02f0..68524ab 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java
@@ -356,7 +356,7 @@ public class HttpServer implements FilterContainer {
if ("http".equals(scheme)) {
listener = HttpServer.createDefaultChannelConnector();
} else if ("https".equals(scheme)) {
- SslSocketConnector c = new SslSocketConnector();
+ SslSocketConnector c = new SslSocketConnectorSecure();
@matteobertozzi
matteobertozzi / ZKAclReset.patch
Last active August 29, 2015 14:21
ZKAclReset erase/set
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java
index 413bc98..16357c1 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java
@@ -1013,10 +1013,15 @@ public class ZKUtil {
}
private static ArrayList<ACL> createACL(ZooKeeperWatcher zkw, String node) {
+ return createACL(zkw, node, isSecureZooKeeper(zkw.getConfiguration()));
+ }
/**
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/IdLock.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/IdLock.java
index b9d0983..8a0ec9b 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/IdLock.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/IdLock.java
@@ -22,6 +22,9 @@ import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.*;
+import java.util.concurrent.*;
https://issues.apache.org/jira/secure/attachment/12739639/IdLockPerf.java
Base IdLock (master)
[T] 16920ms 17.730497op/ms
[T] 17020ms 17.626322op/ms
[T] 17204ms 17.437805op/ms
[T] 17227ms 17.414524op/ms
[T] 17181ms 17.46115op/ms
[T] 17301ms 17.340038op/ms
[T] 17364ms 17.277124op/ms
@matteobertozzi
matteobertozzi / AvlTree.java
Last active January 1, 2019 16:49
AvlTree without parent
private static class Entry<T extends Comparable<T>> {
private Entry<T> avlRight = null;
private Entry<T> avlLeft = null;
private int avlHeight = 1;
private T key;
public Entry(T k) { key = k;}
public int compareKey(T cmpKey) {
@matteobertozzi
matteobertozzi / IterableAvlTree.java
Created November 10, 2015 18:33
Avl Tree with parent
private static class Entry<TKey extends Comparable<TKey>> {
private Entry<TKey> avlParent = null;
private Entry<TKey> avlRight = null;
private Entry<TKey> avlLeft = null;
private int avlHeight = 1;
private final TKey key;
public Entry(TKey key) {
this.key = key;
}
@matteobertozzi
matteobertozzi / raft-leader-election.py
Created December 24, 2015 05:23
Raft Leader Election
from random import randint, shuffle
from uuid import uuid4
from time import time, sleep
import logging
FORMAT = '%(asctime)s %(levelname)s %(funcName)s():%(lineno)d - %(message)s'
logging.basicConfig(format=FORMAT)
LOG = logging.getLogger('raft')